January 27, 2011

issues with script for diskspace and mail monitor

Hi there guys / Girls,

I really seem to only ever post issues on here... :(

anyways, I hope someone can assist,
I found a script to do a Diskspace monitor and notification using shell scripting.

but when I try run it I keep getting a error, First off Im utilizing Red-Hat 5.3 and I am using the script using the root account.

#!/bin/sh
# Shell script to monitor or watch the disk space
# It will send an email to $ADMIN, if the (free avilable) percentage
# of space is >= 80%
# set admin email so that you can get email
ADMIN="Oracle.support@saoutsourcing.com"
# set alert level 80% is default
ALERT=80
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
#echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
echo "System Running low on Disk space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep" $ADMIN
fi
done

the Error I get is

bash: ./DiskSpace_Alert.sh: /bin/sh^M: bad interpreter: No such file or directory

but when looking the /bin/sh does exist

Click Here!