Solved

scripting file understanding

Posted on 2011-03-05
5
295 Views
Last Modified: 2012-05-11
Hi I am trying to understand this file.
can somebody please explain me its bits

[sml@sys19][~] - cat /net/isilon/ifs/systems/bin/check_lics
#!/bin/bash

# Checking for your expirationzzzzzz
#  29.09.2010

# Setting run mode
WARNING=0

# Setting warning threshold in days
THRESHOLD=11

# Give usage if someone provides a crappy parameter
if [[ ! -z $1 ]]; then
        if [[ "$1" = "--warning" ]]; then
                WARNING=1
        else
                echo "Usage $0 [--warning]"
                exit 1
        fi
fi

# Define your ports and servers here
NUKE='@wiretap'
FUSION='/mnt/licserv1/FlexLM/DFusion.dat'
MAYA='27002@plcserv1'
FRANTIC='27000@plcserv1'
DEFAULT='27000@plcserv1'
MOCHA='27003@plcserv1'

# Tell us which of these to check
LICS=(NUKE FUSION MAYA FRANTIC MOCHA DEFAULT)

# This bit actually does the checking
function getlics {
        plcserv1=$1

        TMPFILE=/tmp/lic-checker-temp-$!
        > $TMPFILE

        FEATURE=""; EXPIRY=""; EPOCH=""; NOW=""; REMAIN=""

        # Get the license expiry information out
        /apps/common/bin/lmdiag -c $plcserv1 -n | grep -B 6 'can be checked' | while read LINE; do
                if [[ "$LINE" =~ 'vendor:' ]]; then
                        FEATURE=`echo $LINE | awk '{print $1}' | sed -e 's/"//g'`
                fi
                if [[ "$LINE" =~ 'expir' ]]; then
                        if [[ "$LINE" =~ 'no expiration' ]]; then
                                EXPIRY="Permanent"
                        else
                                EXPIRY=`echo $LINE | awk '{print $NF}'`
                        fi
                fi
                if [[ "$LINE" =~ 'can be checked' ]] && [[ ! "$EXPIRY" =~ 'Permanent' ]]; then
                        # We have all the info we need for a non-perm license now so output it
                        EPOCH=`date --date="$EXPIRY" +%s`
                        NOW=`date --date='now' +%s`
                        REMAIN=`echo "(($EPOCH-$NOW)/86400)+1" | bc`

                        # Only output licenses with a long time until
                        # expiration if it's not in warning mode
                        if [[ "$REMAIN" -lt "$THRESHOLD" ]] || [[ "$WARNING" -eq "0" ]]; then
                                echo -e "$FEATURE \t $EXPIRY \t $REMAIN days remaining" >> $TMPFILE
                        fi

                        # Variable reset for next license
                        FEATURE=""; EXPIRY=""; EPOCH=""; NOW=""; REMAIN=""
                else
                        if [[ "$LINE" =~ 'can be checked' ]] && [[ "$EXPIRY" =~ 'Permanent' ]] && [[ "$WARNING" -ne "1" ]]; then
                                # This is for permanent licenses which are only output if
                                # Not in warning mode
                                echo -e "$FEATURE \t $EXPIRY" >> $TMPFILE

                                # Variable reset for next license
                                FEATURE=""; EXPIRY=""; EPOCH=""; NOW=""; REMAIN=""
                        fi

                fi
        done

        # Flex has a habit of doubling up
        # Only output anything if there's license info to show
        if [[ `cat "$TMPFILE" | wc -l` -ne "0" ]]; then
                echo $2
                cat $TMPFILE | sort | uniq
                echo ""
        fi

        # Get rid of tempfiles
        rm -f $TMPFILE
}

# Main loop
for LIC in "${LICS[@]}"; do
        getlics ${!LIC} $LIC
done
0
Comment
Question by:aashee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
5 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 35044238
#Setting variables to be used later
# Define your ports and servers here
NUKE='@wiretap'
FUSION='/mnt/licserv1/FlexLM/DFusion.dat'
MAYA='27002@plcserv1'
FRANTIC='27000@plcserv1'
DEFAULT='27000@plcserv1'
MOCHA='27003@plcserv1'

MADE A LIST STRUCTURE TO RUN IN A LOOP
# Tell us which of these to check
LICS=(NUKE FUSION MAYA FRANTIC MOCHA DEFAULT)

#Remove all quotations from the line
sed -e 's/"//g'

# This bit actually does the checking
function getlics {
        plcserv1=$1

        TMPFILE=/tmp/lic-checker-temp-$!
        > $TMPFILE

        FEATURE=""; EXPIRY=""; EPOCH=""; NOW=""; REMAIN=""

#Get the output of the script in italics.  If vendor is found, get the first field of the line and remove all quotations.  Save it into the variable FEATURE
        # Get the license expiry information out
        /apps/common/bin/lmdiag -c $plcserv1 -n | grep -B 6 'can be checked' | while read LINE; do
                if [[ "$LINE" =~ 'vendor:' ]]; then
                        FEATURE=`echo $LINE | awk '{print $1}' | sed -e 's/"//g'`
                fi
if expir is found in a line, check it also has no expiration.  If so, variable EXPIRY is set to Permanent, otherwise, it is set to the last field of the line

                if [[ "$LINE" =~ 'expir' ]]; then
                        if [[ "$LINE" =~ 'no expiration' ]]; then
                                EXPIRY="Permanent"
                        else
                                EXPIRY=`echo $LINE | awk '{print $NF}'`
                        fi
                fi
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35044306
If a line contains can be checked and variable EXPIRY for this line doesn't contain the word Permanent then EPOCH would be the numbers of seconds since 1970 and NOW is also the number of seconds since 1970.  Subtracting both and dividing by the number of seconds in a day 86400, would be the REMAIN (add one day to it by using a calculator bc
if [[ "$LINE" =~ 'can be checked' ]] && [[ ! "$EXPIRY" =~ 'Permanent' ]]; then
                        # We have all the info we need for a non-perm license now so output it
                        EPOCH=`date --date="$EXPIRY" +%s`
                        NOW=`date --date='now' +%s`
                        REMAIN=`echo "(($EPOCH-$NOW)/86400)+1" | bc`

#If the remaining number of days is less than the THRESHOLD value OR WARNING is zero, put value of FEATURE <tab> EXPIRY <tab> REMAIN days remaining into the temp file set above.  The words in capitals are variables
                        # Only output licenses with a long time until
                        # expiration if it's not in warning mode
                        if [[ "$REMAIN" -lt "$THRESHOLD" ]] || [[ "$WARNING" -eq "0" ]]; then
                                echo -e "$FEATURE \t $EXPIRY \t $REMAIN days remaining" >> $TMPFILE
                        fi

                        # Variable reset for next license basically setting variables to nothing
                        FEATURE=""; EXPIRY=""; EPOCH=""; NOW=""; REMAIN=""
                else
                        OTHERWISE
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35044367
This is otherwise to the first condition where it was checking if [[ "$LINE" =~ 'can be checked' ]] && [[ ! "$EXPIRY" =~ 'Permanent' ]]
If the line contains the phrase can be checked, EXPIRY variable contains 'Permanent' and WARNING variable is not one.
Put in the TEMPFILE value of <FEATURE <tab> EXPIRY <tab>

if [[ "$LINE" =~ 'can be checked' ]] && [[ "$EXPIRY" =~ 'Permanent' ]] && [[ "$WARNING" -ne "1" ]]; then
                                # This is for permanent licenses which are only output if
                                # Not in warning mode
                                echo -e "$FEATURE \t $EXPIRY" >> $TMPFILE

                                # Variable reset for next license
                                FEATURE=""; EXPIRY=""; EPOCH=""; NOW=""; REMAIN=""
                        fi

                fi
        done
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35044384
#Read the temp file only if it contains something.  Then display the second parameter followed by the file with sorted and no duplicate lines
 # Flex has a habit of doubling up
        # Only output anything if there's license info to show
        if [[ `cat "$TMPFILE" | wc -l` -ne "0" ]]; then
                echo $2
                cat $TMPFILE | sort | uniq
                echo ""
        fi

       # Get rid of tempfiles
        rm -f $TMPFILE
0
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 35044404
Looping through all the servers/ports declared above

# Main loop
for LIC in "${LICS[@]}"; do
        getlics ${!LIC} $LIC
done
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux FTP Error 5 59
SMTP log file for IMSVA 5 75
phpmyadmin memory error 55 95
subtract to time in .bash file 2 8
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question