return to PRS Technologies website


check_new_segments.sh
#!/bin/sh ############################################################################### # # Module: check_new_segments.sh # Author: Peter R. Schmidt # # Description: # # Check to see if any new Informix shared memory virtual segments have been added. # # Change Log # # Date Who Description # # 10/17/2000 Peter Schmidt Start Program # 02/20/2001 Peter Schmidt Make sure Informix is up and the previous file exists ($LASTCNT > 0) # ################################################################################ EXCLUDE_LIST1="^$|^TIMESTAMP:|Informix Dynamic|Segment Summary|Total\:|class blkused blkfree|locked in memory" #------------------------------------------------------------------------------- # Set the Informix environment #------------------------------------------------------------------------------- ENV_FILE=/usr/local/bin/setenv.sh if [ -x $ENV_FILE ] then . $ENV_FILE > /dev/null else echo "Error: the file used to set the Informix environment does not exist!" echo "The missing filename is: $ENV_FILE" exit 1 fi if [ "x$INFORMIXDIR" = "x" ] # Is my environment already set ? then # Note: You can set the Informix environment several ways. # You can hardcode it here - or else you can set it using a file. # If you hardcode it here, it would look something like this... # #export INFORMIXDIR=/opt/informix #export INFORMIXSERVER=myserver_shm #export ONCONFIG=onconfig.myserver # If you set it using a file, it might look like this... ENV_FILE=/usr/local/bin/setenv.sh if [ -x $ENV_FILE ] then . $ENV_FILE else echo "Error: the file used to set the Informix environment does not exist!" echo "The missing filename is: $ENV_FILE" exit 1 fi fi INFORMIXHOME=${INFORMIXHOME:-"/home/informix"} LASTTIME=$INFORMIXHOME/logs/onstat_g_seg.last THISTIME=$INFORMIXHOME/logs/onstat_g_seg.new #------------------------------------------------------------------------------- # Check to make sure this directory exists #------------------------------------------------------------------------------- if [ ! -d $INFORMIXHOME/logs ] then echo "Error: $0: the directory $INFORMIXHOME does not exist!" echo "I don't know where to put the output from the last onstat -g seg." exit 1 fi #------------------------------------------------------------------------------- # Make sure the instance is up. If not - then just exit. #------------------------------------------------------------------------------- if [ `$INFORMIXDIR/bin/onstat 2>&- | /usr/bin/grep -c "not initialized"` -ne 0 ] then exit 0 fi #------------------------------------------------------------------------------- # Get previous number of virtual segments #------------------------------------------------------------------------------- LASTCNT=0 if [ -f $LASTTIME ] then for CLASS in `cat $LASTTIME | egrep -v "$EXCLUDE_LIST1" | awk '{print $6}'` do if [ $CLASS = "V" ] then LASTCNT=`expr $LASTCNT + 1` fi done fi #------------------------------------------------------------------------------- # Save latest number of segments #------------------------------------------------------------------------------- NEWDATE=`date` echo "TIMESTAMP: $NEWDATE" > $THISTIME onstat -g seg >> $THISTIME #------------------------------------------------------------------------------- # Get the latest number of virtual segments #------------------------------------------------------------------------------- NEWCNT=0 for CLASS in `cat $THISTIME | egrep -v "$EXCLUDE_LIST1" | awk '{print $6}'` do if [ $CLASS = "V" ] then export NEWCNT=`expr $NEWCNT + 1` fi done #------------------------------------------------------------------------------- # Compare the counts #------------------------------------------------------------------------------- if [ $NEWCNT -gt $LASTCNT -a $LASTCNT -gt 0 ] then echo "Attention: the number of Informix shared memory Virtual segments has increased!" echo echo "The Virtual segment count increased from $LASTCNT to $NEWCNT" echo echo "--------------------------------------------------------------------------------" echo "PREVIOUS segment summary" cat $LASTTIME echo "--------------------------------------------------------------------------------" echo "LATEST segment summary" cat $THISTIME echo "--------------------------------------------------------------------------------" echo fi #------------------------------------------------------------------------------- # Replace the file for the next check # Note: if the NEW count is smaller then the LAST count, that implies # that the Informix engine was bounced or segments were freed up. No problem. #------------------------------------------------------------------------------- rm -f $LASTTIME mv $THISTIME $LASTTIME