Skip to content

Instantly share code, notes, and snippets.

@ashfurrow
Last active October 21, 2017 21:37
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 ashfurrow/553b2ea2a0cd2a2007e46c40615311d6 to your computer and use it in GitHub Desktop.
Save ashfurrow/553b2ea2a0cd2a2007e46c40615311d6 to your computer and use it in GitHub Desktop.
Script to check for low disk space on a DigitalOcean volume
#!/bin/sh
df -H | grep '/mnt/volume-nyc1-01' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 80 ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"
curl -s --user "api:$MAILGUN_API_SECRET" \
https://api.mailgun.net/v3/mastodon.technology/messages \
-F from='Mastodon Host <root@mastodon.technology>' \
-F to=ash@ashfurrow.com \
-F subject="Low Disk Space ($usep%)" \
-F text="Running out of space on $(hostname) as of $(date)"
fi
done
# Note this doesn't work on all distros :shrug:
MAILGUN_API_SECRET='...'
0 * * * * /root/check_disk_space.sh
@ashfurrow
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment