Welcome to the new Linux Foundation Forum!

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="[email protected]"
# 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

Comments

  • hey,

    i guess the issue is not with existence of /bin/sh file but with character '^M' that is present in the script. If you see the error it says something like " /bin/sh^M " so let me guess did u copy the script from windows file to unix box?
    if so then before executing type teh below command-

    #dos2unix <script_name>

    cheers,
    blue_raptor
Sign In or Register to comment.