Monitor FlexLM Licenses Status using Bash scripts

Overview

Monitor FlexLM Licenses Status using Bash scripts.
FlexLM is a License Manager by FlexNet.

Monitor FlexLM Licenses Status using Bash scripts

Requirements

– Linux Server/Desktop (we’ll use CentOS and we’ll call it CheckServer)
– Linux Server/Desktop hosting licenses (we’ll use CentOS and we’ll call it Server01)
– FlexNet / FlexLM Utils

As an IT pro you’ll most likely need to use a floating license at some point.
FlexLM is quite easy to operate but monitoring it is a different matter.

We will use CentOS 6.2 (you can use any linux/unix distro as long as it supports lmutil and lmstat)

Get lmutil and lmstat

Download lmutil and lmstat from Flex and place it in your /usr/bin/

1
2
chmod +x /usr/bin/lmutil
chmod +x /usr/bin/lmstat
chmod +x /usr/bin/lmutil
chmod +x /usr/bin/lmstat

Create the license list file license-check.lst

1
vi /scripts/lst/license-check.lst
vi /scripts/lst/license-check.lst

Create a file that looks like this App name port@server, for example:
Agilent 2100@Server01
Altera 2200@Server01
Xilinx 2500@Server01
Mentor 2100@Server02
Orcad 2200@Server02
Synopsys 2300@Server02

* you can specify several servers and ports in the same lst file.

Create the script

1
vi /scripts/license-check.sh
vi /scripts/license-check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
 
workdir=/scripts
logfile=$workdir/tmp/license-check.run
listfile=$workdir/lst/license-check.lst
finallogfile=$workdir/log/license-check-$(date +%y%m%d)
emailfile=$workdir/license-check.email
 
(
cd $workdir/
if [ -a $logfile ] ; then
    echo ""
    echo "Script is Running! check " $logfile
    echo ""
    exit; 
fi
 
cat $listfile | while read line
do
    appname=$(echo $line | awk '{print $(NF-1)}')
    portserver=$(echo $line | awk '{print $NF}')
    /usr/bin/lmutil lmstat -a -c $portserver |grep Error
    if [ $? != 1 ] ; then
        echo $appname license DOWN - $portserver >> $emailfile
        echo "================================================================================"
        echo $appname license DOWN - $portserver
        echo "================================================================================"
    else
        echo "================================================================================"
        echo $appname license OK - $portserver
        echo "================================================================================"
    fi
done
echo ""
echo "**************************************"
echo "*****           All Done         *****"
echo "**************************************"
echo ""
) 2>&1 | tee -a $logfile
mv $logfile $finallogfile
 
if [ -a $emailfile ] ; then 
    echo "Sending error log..."
    echo "**************************************"
    cat $emailfile
    echo "**************************************"
    cat $emailfile |mail -s "licenses check on Server01 " support@mail.com
    rm -f $emailfile
fi
#!/bin/bash

workdir=/scripts
logfile=$workdir/tmp/license-check.run
listfile=$workdir/lst/license-check.lst
finallogfile=$workdir/log/license-check-$(date +%y%m%d)
emailfile=$workdir/license-check.email

(
cd $workdir/
if [ -a $logfile ] ; then
    echo ""
    echo "Script is Running! check " $logfile
    echo ""
    exit; 
fi

cat $listfile | while read line
do
	appname=$(echo $line | awk '{print $(NF-1)}')
	portserver=$(echo $line | awk '{print $NF}')
	/usr/bin/lmutil lmstat -a -c $portserver |grep Error
	if [ $? != 1 ] ; then
	    echo $appname license DOWN - $portserver >> $emailfile
	    echo "================================================================================"
	    echo $appname license DOWN - $portserver
	    echo "================================================================================"
	else
	    echo "================================================================================"
	    echo $appname license OK - $portserver
	    echo "================================================================================"
	fi
done
echo ""
echo "**************************************"
echo "*****           All Done         *****"
echo "**************************************"
echo ""
) 2>&1 | tee -a $logfile
mv $logfile $finallogfile

if [ -a $emailfile ] ; then 
    echo "Sending error log..."
    echo "**************************************"
    cat $emailfile
    echo "**************************************"
    cat $emailfile |mail -s "licenses check on Server01 " support@mail.com
    rm -f $emailfile
fi

Manage automatic checkup

For example run the ‘license-check.sh’ script every Day at 07:00 :

1
crontab -e
crontab -e
1
0 7 * * * /scripts/license-check.sh
0 7 * * * /scripts/license-check.sh

This is an explanation of crontab:

Minute Hour Day of Month Month Day of Week Command
(0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)

Leave a Reply

Your email address will not be published.

*