Filter löschen
Filter löschen

Check availability of floating license

40 Ansichten (letzte 30 Tage)
Patrick Schmale
Patrick Schmale am 21 Apr. 2017
Kommentiert: Davide Allaio am 14 Mär. 2023
We are using MATLAB/Simulink floating license for continous integration. We've got the problem that MATLAB/Simulink ends up with an license checkout failed error, if no floating license is available. Is there a way to check if a license is a available before starting MATLAB/Simulink?

Akzeptierte Antwort

Antonios Pournaras
Antonios Pournaras am 27 Jul. 2018
Here is a python function that prints how many licences are available and returns in this case. If there are no licenses available it tries again. The function calls the system command "lmutil" which is a license administration utility installed along with MATLAB. It writes the output to a file 'mat_lic.info'. Parses this file until it finds a line where there is information about the licence. Always check this file because its format may change through different MATLAB versions and the script needs modification. It works for MATLAB R2014b:
import subprocess
def matlab_license():
while True:
# substitute port and server with correct values
# lmutil may not be in path. Put the whole path instead.
lic_server=['lmutil','lmstat','-a','-c','port@server']
cmdout = subprocess.check_output(lic_server)
F=open('mat_lic.info','w')
F.write(cmdout)
F.close()
F=open('mat_lic.info','r')
for line in F:
if 'Users of MATLAB' in line:
text = line
break
F.close()
num=[]
for word in text.split():
if word.isdigit():
num.append(word)
lic_avail = max(num) - min(num)
if lic_avail < 2:
print "Only %d licence(s) found. Trying again." % lic_avail
else:
print "Found %d licenses availabe." % lic_avail
return
  2 Kommentare
Patrick Schmale
Patrick Schmale am 6 Aug. 2018
Bearbeitet: Patrick Schmale am 6 Aug. 2018
Thanks for your reply. Meanwhile I wrote a similar PowerShell script doing the same:
# Powershell-Script to detect if an MATLAB/Simulink license is available
# If no license is avaiable the scripts sleeps for 15min and repeats the check
$licenseFile = "<Full-Path of License-File>.dat"
$licenseInfo = lmutil.exe lmstat -a -c $licenseFile | Select-String -Pattern 'Total of 0 licenses in use'
while($licenseInfo.Matches.Count -ne 2){
Write-Host "No MATLAB/Simulink license availabe. Repeat after 15min..."
Start-Sleep -s 900
$licenseInfo = lmutil.exe lmstat -a -c $licenseFile | Select-String -Pattern 'Total of 0 licenses in use'
}
Davide Allaio
Davide Allaio am 14 Mär. 2023
Hello, I know it has been 5 years already, but could someone explain to me how to modify the lic_server string correctly in order for the function to work? Thank you very much!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Megha Parthasarathy
Megha Parthasarathy am 25 Apr. 2017
Hello,
Refer to this link that talks about monitoring licenses.
  1 Kommentar
Patrick Schmale
Patrick Schmale am 26 Apr. 2017
Hi,
thanks for your help. Running
lmutil lmstat -a -c %licenseFile%
just prints out the license information on the console. But I need some kind of environment variable telling me if a license is avaiable. Do you know how I can achieve this?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Manage Products finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by