df-alert (743B)
1 #!/bin/bash 2 3 EMAIL=${1:-a3nm@localhost} 4 THRESHOLD=${2:-97} 5 6 function do_check() { 7 CURRENT=$(df "$1" | grep / | awk '{ print $5}' | sed 's/%//g') 8 9 if [ "$CURRENT" -gt "$THRESHOLD" ] ; then 10 mail -s "[df-alert] `hostname`:$1 using $CURRENT%" "$EMAIL" << EOF 11 df-alert notification: `hostname`:$1 uses $CURRENT% 12 EOF 13 fi 14 } 15 16 do_check '/' 17 do_check '/home' 18 19 # encrypted partition on raspberry pi 20 if [ -d /data ] 21 then 22 do_check '/data' 23 fi 24 25 # other disks 26 df -t ext4 | awk '{print $6}' | grep '^/mnt' | while read l 27 do 28 NAME=$(echo "$l" | rev | cut -d '/' -f1 | rev) 29 # do not watch disk space on disks that are only used for backups 30 if ! grep -q "$NAME" "$HOME/config/private/disks_backup" > /dev/null 31 then 32 do_check "$l" 33 fi 34 done 35