Skip to content

Instantly share code, notes, and snippets.

@eykanal
Created June 27, 2011 14:35
Show Gist options
  • Save eykanal/1048970 to your computer and use it in GitHub Desktop.
Save eykanal/1048970 to your computer and use it in GitHub Desktop.
Monitor disk space, send email when reaches
#!/bin/sh
# How full should the disk be allowed to get (percentage)?
warn_at=90
# get disk space info for all disks
df | grep "/dev/disk" | awk '{ print $1,$3,$4,$5,$6 }' > /tmp/space
# for each disk, determine if full
while read line
do
used=`echo $line | cut -f2 -d ' '`
free=`echo $line | cut -f3 -d ' '`
percent=`echo $line | cut -f4 -d ' '`
dirname=`echo $line | cut -f5 -d ' '`
perc=`echo "$used/($free+$used)*100" | bc -l | sed 's/\.[0-9]*//'`
if [ $perc -ge $warn_at ]
then
echo Warning! $dirname is $perc percent full! \
| mailx -s 'disk getting full!' [email protected]
fi
done < /tmp/space
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment