Monitor FlexLM License Status with Bash

Monitor FlexLM License Status with Bash

Overview

A Bash script that automatically monitors FlexLM (FlexNet) license server status across multiple applications and sends email alerts when a license goes down.

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/

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

Create the license list file 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

vi /scripts/license-check.sh
#!/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 :

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

This is an explanation of crontab:

MinuteHourDay of MonthMonthDay of WeekCommand
(0-59)(0-23)(1-31)(1-12 or Jan-Dec)(0-6 or Sun-Sat)