Detect if user has a valid MatLab license
Show older comments
We're writing a shell script that we want to have it check if the user has a valid MATLAB license. If they do, the script will launch a MATLAB function call from the command line, otherwise it will call an equivalent (but slower) numpy script.
On most of our users' Linux machines, they have their MATLAB license stored under /home/<user>/.matlab/R2021a_licenses. These cases are easy to deal with. However, on some of the machines, the user licenses were installed under /usr/local/MATLAB/R2021a/licenses. On those machines, licenses for multiple users are stored under that directory. For example, we might have a machine where users foo and bar have valid license files, but user baz does not. If I look in /usr/local/MATLAB/R2021a/licenses I might see the following files:
license_MyHost_123456_R2021a.lic, license_MyHost_987654_R2021a.lic
I've looked at the contents of the license file and there doesn't seem to be a human-readable username listed in there, just the license number. So when users foo, bar, and baz each run my bash shell script, is there anything I can key off to determine that users foo and bar do have a license so my script should use the MATLAB path, and baz does not have a MATLAB license, so they get the numpy version? Ideally maybe knowing which of the two license files goes with which user might also be helpful too - identifying that user foo specifically has license 123456, might be helpful too since then I could maybe offer them the option of copying that license file down into /home/foo/.matlab/R2021a_licenses
6 Comments
This might be helpful.
ver
Walter Roberson
on 19 Jan 2023
I am not aware of any way that a license number can show up as 0
Sean Murphy
on 19 Jan 2023
Walter Roberson
on 19 Jan 2023
@Mario Malic posted an example of ver with MATLAB License Number: 0 shown. As far as I known, license number 0 is not possible for any valid license.
Sean Murphy
on 19 Jan 2023
license
Answers (3)
Fangjun Jiang
on 19 Jan 2023
Edited: Fangjun Jiang
on 19 Jan 2023
1 vote
There are so many ways to specify the license file, I think you need to follow this order specified in "MATLAB License Search Path" in this link.
Instead, I would suggest launching MATLAB directly. If not successful, then use Python.
2 Comments
Sean Murphy
on 19 Jan 2023
Fangjun Jiang
on 20 Jan 2023
@Jan has pointed out the expired license or offline with license server.
One more complication, a license file could be license.dat or any *.lic file.
Walter Roberson
on 19 Jan 2023
Moved: Walter Roberson
on 19 Jan 2023
0 votes
If I look in /usr/local/MATLAB/R2021a/licenses I might see the following files:
license_MyHost_123456_R2021a.lic, license_MyHost_987654_R2021a.lic
In /usr/local/MATLAB/R2021a/licenses you should only see three kinds of licenses:
- trial licenses can go there
- Dedicated Host licenses can go there
- Network licenses (that contain nothing user-specific) can go there
Individual user licenses will not go there.
A license file name format such as license_MyHost_123456_R2021a.lic in that directory would be used for a Dedicated Host license for host name MyHost with MAC address 123456 (if this were Windows then instead of MAC address there could be a disk serial number.) However at the moment I cannot rule out the possibility that they are trial licenses.
Those are not individual user licenses -- not unless your system has been configured with an LM_LICENSE environment variable that points to /usr/local/MATLAB/R2021a/licenses . If so, then in that particular case, the 123456 would be the Mathworks license number. Unfortunately if that is the case, then those files would not contain any information about username. And in such a situation, MATLAB would go through all of the .lic files in directory order, checking to see if someone else is already using that license, and grabbing the first one that is not in use. Which is not how you would want to configure a group of individual Standalone Named User licenses, but that is what would happen if someone did configure that way. (I believe.)
Jan
on 19 Jan 2023
0 votes
The detection is not trivial. A matching license file might be there, but the license can be expired. The computer or license server might be offline.
The best way to check, if a user can run Matlab is to call Matlab and check the succeess. If it fails, your program can store a flag in its settings to avoid following checks.
4 Comments
Sean Murphy
on 19 Jan 2023
Jan
on 20 Jan 2023
@Sean Murphy: Even if you find a license file (or several of them), the call to Matlab can fail: Missing toolbox, expired license, bad configuration (crashing startup function) or too old version. Therefore you need an error handling at all, which catchs the problem and calls the workaround.
This error handling solves the problem of the license check exhaustively already. So introducing this check is an unneeded source of bugs only.
Sean Murphy
on 20 Jan 2023
Jan
on 22 Jan 2023
@Sean Murphy: Yes, of course a check is not inaproppriate. Keep in mind that there can be more ways to run Matlab successfully than you are aware of. Only a successful run of Matlab is a reliable proof, that Matlab runs successfully, which include all kind of versions to perform the license check. Finding a license file is no trustworthy evidence, that the Matlab license is working.
There have been generic license files form Matlab 7, which can be provided from individual locations, which are defined by command line arguments.
Automatic tests are based on assumptions. Maybe letting the user decide actively is more reliable, e.g. with a "-useMatlab" flag in the command line or by a dialog window.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!