A message for Linux.com registered users: We are in the process of making changes to the Linux forums. Starting Monday, 8/13/18 at 6:00 PM PT, you will be unable to access the forums. They will re-launch as soon as possible on Wednesday, 8/15/18 with new features and improved functionality. Thank you for your patience and stay tuned for the new improved forums.

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.

# 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
# set alert level 80% is default
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
#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

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!