#!/bin/ksh # This script searches for file-systems with ocuppation greater than 90% # If there is one or more file-systems in that condition, then knowledge the # System Administrators( $ADMIN variable ). # # I think that itīs a good idea to put this kind of monitoring script into # the crontab. It can actually work with IBMīs AIX and SUNīs Solaris. Any # comments or enhancements are welcome. # mail: tsuba@osite.com.br or humberto.tadashi.tsubamoto@br.abnamro.com # Set some variables necessari to create temporary files TMPDIR=tmp TMPARQ=monit_fs.tmp ADMINS="root root" # This function is responsible for sending messages to System Administrators` # terminal and sendim mail to their mailboxes. alert () { for u_name in $ADMINS do # Sends messages to an user Terminal. for terminal in `who | grep $u_name | awk '{print $2}'` do AUX=`who | grep $u_name` [ -z "$AUX" ] && continue write $u_name $terminal << EOF 2> /dev/null There are some file systems with capacity usage greater than 90%!! Look at your mailbox!!! EOF done # Sends mail to an user. mailx $u_name << EOF 2> /dev/null The following file systems have used space greater than 90%!! `cat /$TMPDIR/$TMPARQ` . EOF done } # Unfortunately dfīs unix utility output is OS dependent. So this function # looks at system type (AIX, SunOS) and exports a variable with the machineīs # file-systems list sist_op () { SO=`uname -s` case $SO in AIX ) export LST_FS=`df -k |grep dev|awk '{print $7}'` ;; SunOS ) export LST_FS=`df -k |grep dev|awk '{print $6}'` ;; * ) echo "Unknown Operating System!!!" exit 0 ;; esac } # According to system type (AIX, SunOS), sets the PERCENT variable with # percentual used space. (without % symbol) perc () { case $SO in AIX ) PERCENT=`df -k $FS|grep dev|awk '{print $4}' |sed "s/\%/""/g"` ;; SunOS ) PERCENT=`df -k $FS|grep dev|awk '{print $5}' |sed "s/\%/""/g"` ;; * ) echo "Unknown Operating System!!!" exit 0 ;; esac } # Sets the CRITICAL variable, which determines if the alert() function will # be executed. CRITICAL=0 sist_op # Verify each file-system, putting in /$TMPDIR/$TMPARQ file the ones which # have ocuppation greater than 90% for FS in $LST_FS do perc if [ $PERCENT -gt 90 ] ; then echo "Ocupation in File System $FS is in $PERCENT%">>/$TMPDIR/$TMPARQ CRITICAL=1 fi done # If CRITICAL equal to 1 then there are file-systems with space problems. # So, we need to execute alert() function to knogedge the System Administrators if [ $CRITICAL = 1 ] ; then alert fi # Removes the temporary file rm -f /$TMPDIR/$TMPARQ 2>/dev/null