Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Disk monitoring script that will alert you when one of your disks has little space left
#!/bin/bash
# Add this script as a cronjob
# Append the following line to your cronjob file (open cronjob file with `crontab -e`):
# @daily /path/to/disk-monitor.sh
SIMPLEPUSH_KEY=YourKey
THRESHOLD=90
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read line;
do
percentage=$(echo $line | awk '{ print $1}' | cut -d'%' -f1 )
disk=$(echo $line | awk '{ print $2 }' )
if [ $percentage -ge $THRESHOLD ]; then
curl --silent --output /dev/null --data "key=$SIMPLEPUSH_KEY&title=$disk&msg=Disk usage at $percentage%!" https://api.simplepush.io/send
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment