Remote disk space monitor

The following is a poor man’s disk space monitor script.
“ssh id@host df -h ” is the core of the script. It relies on SSH RSA authentication so that the remote “df” can work like local.

#!/bin/ksh
homedir=`dirname $0`
RUN_DATE_LONG=$(date +’%Y%m%d’)
LOGFILE=${homedir}/diskmon_log.$RUN_DATE_LONG

HOSTS=”192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 ”

alert=90
alert_email=”admin@foo.com”
typeset -i email=0

function rdf
{
echo “$1 is sshing into $2 doing a df…….” >> $LOGFILE
ssh $1@$2 df -hP | grep -vE ‘^Filesystem’ | awk ‘{print $4 ” ” $5 ” ” $1 ” ” $2}’ | while read line;
do
typeset -i used=$(echo $line | awk ‘{print $1}’ | cut -d “%” -f 1)
if [[ $used -ge $alert ]]; then
email=1
echo $line >> $LOGFILE
fi
done
echo “ssh done…….” >> $LOGFILE
}

for h in $HOSTS
do
rdf sshid $h
done

if [[ ${email} -eq 1 ]]; then
echo “alert email will be setnt” >> $LOGFILE
# put whatever mailer you use here
fi

Advertisements
This entry was posted in diskmon. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s