Check Disk space usage
Posted: Mon Jan 23, 2012 1:58 pm
Code: Select all
#!/bin/bash
# Script: chk_disk_space.sh
# Author: Troy Hockman
# Desc: Checks diskspace
# cronjob=30 * * * * /opt/Scripts/chk_disk_space.sh > /dev/null 2>&1
#
spthres=80
smailf="/opt/Scripts/sendEmail"
eto="admin@test.com"
ecc="anotheradmin@test.com"
efrom=diskAlert@test.com
eserver=intmail.test.com
esubject="Diskspace Alert for `hostname`."
clear
parts=$(df -lhP | awk '{print $1 "--" $5}' | grep -v Use | sed s/\%//g)
for i in $parts; do
use=$(echo $i | awk 'BEGIN {FS = "--"} ; { print $2}')
part=$(echo $i | awk 'BEGIN {FS = "--"} ; { print $1}')
if [[ "$use" > "$spthres" ]]; then
body1="$part on `hostname` appears to be over the set threshold of $spthres%.\n\n"
body2="The current usage is $use%.\n\n"
body3="This alert will be sent every thirty minutes until fixed!"
ebody="$body1$body2$body3"
$smailf -u $esubject -m $ebody -f $efrom -t $eto -cc $ecc -s $eserver
fi
done