Listing 1. Simple Agent
# the name of the EMU server
EMUSERVER=emuserver.company.com.au
# port the EMU server listens on
PORT=2345
#temporary file used for report output
TMP=/tmp/df.out
# print a filesystem report into a temporary file
df -k | grep -vi available > $TMP
# Internal Field Separator must be set to a new
# line to correctly process entries in $TMP
oldIFS=$IFS
IFS='
'
# get file systems one at a time
# for LINE in `cat $TMP`
do
# get the file system name
FS=`echo $LINE | awk '{print $6}'`
# calculate the remaining disk space
FREESPACE=`echo $LINE | sed 's/%//'| \
awk '{fs=100-$5; if (fs >=0) \
{print 100-$5}else {print 0}}'`
# if remaining diskspace is less than 10 %,
#send a message
if [ $FREESPACE -lt 10 ];then
emsg -n $EMUSERVER -p $PORT -t 6m -s 1\
-c /LINUX/FS -m\
"$FS has less than ${FREESPACE}% free space"
fi
done
Copyright © 1994 - 2018 Linux Journal. All rights reserved.