Skip to content

Instantly share code, notes, and snippets.

@simplepush
Created November 3, 2021 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simplepush/af1b9c87e9203664fbd40b7bb300175a to your computer and use it in GitHub Desktop.
Save simplepush/af1b9c87e9203664fbd40b7bb300175a to your computer and use it in GitHub Desktop.
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