jeff-j of osxroot
2/21/2015 - 8:14 PM

checks startup disk, sends warning if usage goes above x %

checks startup disk, sends warning if usage goes above x %

#!/bin/bash

# this script sends an email if the startup drive goes over x% used

# send email to this address
email=""

# Warn if usage goes over this amount
warn=90


usep=`df -hl / | tail -1  | awk '{ print $5 }' | sed 's/[^0-9]*//g'`
avail=`df -hl / | tail -1  | awk '{ print $4 }'`



if [ $usep -gt $warn ]; then
 echo
 echo -e "The startup drive is running low on space: ($usep%) full with ($avail) remaining\n$(hostname)" |
 tee /dev/stderr |
 mail -s "Startup drive almost full on $(hostname)" $email
 echo
else
 echo -e "\nNormal: The startup drive is ($usep%) full with ($avail) remaining\n"
fi

exit 0