#!/bin/ksh # # Check Load Korn Shell Script for Solaris 2.x # (c) Copyright Oct 1997 Peter Beckman # # This program uses the program 'uptime' to grab the load of the system. # It expects data similar to this: # 2:37PM up 20:47, 1 user, load averages: 0.16, 0.11, 0.05 # It splits on the "g" of averages, and then again on the : to get the # actual numbers, then splits it more for each value # (1 minute, 5 minute, 15 minute averages). # # Uses: # /usr/local/bin/top (ftp.groupsys.com/pub/top or # eecs.nwu.edu/pub/top) # /usr/bin/mailx # /usr/bin/awk # /usr/bin/uptime # # For more useful shell scripts, check out 'sysadmin central' # http://www.purplecow.com/sysadmin/ # ################################################## # Edit the following variables for your own site # ################################################## # Host HOST=`/usr/bin/hostname` # Who to e-mail EMAILEES="admin" # Who to page PAGEES="redalert" # Log file LOG="/var/log/load_log" # Set thresholds of load (in processes waiting for CPU) LOW_LOAD=2 MED_LOAD=4 HIGH_LOAD=6 DATE=`date` NOTICE='' STATUS='' # Get the real 5 minute average load UPTIME=`uptime` LOAD_1=`echo $UPTIME | awk -F"g" '{print $2}' | awk -F":" '{print $2}' | awk -F"," '{print $1}'` LOAD_5=`echo $UPTIME | awk -F"g" '{print $2}' | awk -F":" '{print $2}' | awk -F"," '{print $2}'` LOAD_15=`echo $UPTIME | awk -F"g" '{print $2}' | awk -F":" '{print $2}' | awk -F"," '{print $3}'` # Test it if [ $LOAD_5 -ge $HIGH_LOAD ]; then NOTICE=$NOTICE"CRITCAL CONDITION: The Load on $HOST is at $LOAD_5!!!\n\n" STATUS="CRITICAL" elif [ $LOAD_5 -ge $MED_LOAD ]; then NOTICE=$NOTICE"SERIOUS CONDITION: The Load on $HOST is at $LOAD_5!!!\n\n" STATUS="SERIOUS" elif [ $LOAD_5 -ge $LOW_LOAD ]; then NOTICE=$NOTICE"HURTING CONDITION: The Load on $HOST is at $LOAD_5!!!\n\n" STATUS="HURTING" fi if [ ${#NOTICE} -ne 0 ]; then echo "${DATE}: ${NOTICE}" >> /var/log/load_log if [ $STATUS = "CRITICAL" ] || [ $STATUS = "SERIOUS" ]; then /usr/local/bin/top -b | /usr/bin/mailx -s "$HOST $STATUS: Load at $LOAD_5!!!" $PAGEES # echo "Load Critical: Paging $PAGEES..." else /usr/local/bin/top -b | /usr/bin/mailx -s "$HOST $STATUS: Load at $LOAD_5!!!" $EMAILEES # echo "Load Bad: Mailing $EMAILEES..." fi fi