https://www.phpini.com/linux/shell-script-check-harddisk-usage
Shell Script 監測硬碟使用量
#!/bin/bash
toemail="you@youremail.com"
alert=90
df -H | grep -vE ‘^Filesystem|tmpfs’ | awk ‘{ print $5 " " $6 }’ | while read output;
do
usepercent=$(echo $output | awk ‘{ print $1}’ | cut -d’%’ -f1 )
partition=$(echo $output | awk ‘{ print $2 }’ )
if [ $usepercent -ge $alert ]; then
echo "$(date): $(hostname) Disk Space Alert: \"$partition ($usepercent%)\"" |
mail -s "$(hostname) Disk Space Alert" $toemail
fi
done
0 0 * * * /path/to/check-disk.sh > /dev/null 2>&1