Last active
October 21, 2017 21:37
-
-
Save ashfurrow/553b2ea2a0cd2a2007e46c40615311d6 to your computer and use it in GitHub Desktop.
Script to check for low disk space on a DigitalOcean volume
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <[email protected]>' \ | |
-F [email protected] \ | |
-F subject="Low Disk Space ($usep%)" \ | |
-F text="Running out of space on $(hostname) as of $(date)" | |
fi | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note this doesn't work on all distros :shrug: | |
MAILGUN_API_SECRET='...' | |
0 * * * * /root/check_disk_space.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on: https://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html