Shell script to notify Hard disk space utilization
The below script will check the hard disk space usage, using the command du and send an email alert if any of the partition is using more than 85% of space.
vim disk-usage.sh
#!/bin/sh
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 85 ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep%" example@example.com
fi
done
Set a cronjob to run this script.
*/30 * * * * /bin/sh /path-to-file/disk-usage.sh
Posted by Shahid
3 responses to "Shell script to notify Hard disk space utilization"
21:47 on February 9th, 2010
I tried the below in AIX.. it works.. but sending blank mails when the space is below
#Space check Script
Notes_space=`df -g| awk ‘{ if ($4 > 50 ) {print $0 } }’`
echo “$Notes_space”|mailx -s “test mail for diskspace” -r “sender” recepient@xyz.com
10:12 on February 10th, 2010
@Vikram
Make sure the variable ‘$Notes_space’ has some value.