Skip to content

Instantly share code, notes, and snippets.

@avtehnik
Last active February 15, 2017 09:29
Show Gist options
  • Save avtehnik/c7e39510067c207e70f5 to your computer and use it in GitHub Desktop.
Save avtehnik/c7e39510067c207e70f5 to your computer and use it in GitHub Desktop.
check free space and send email if not enough
{
"Data": "From: [email protected]\nTo: [email protected]\nSubject:Disk space filled up \nMIME-Version: 1.0\nContent-type: Multipart/Mixed; boundary=\"NextPart\"\n\n--NextPart\nContent-Type: text/plain\n\nThis is the email to notify that the space in the disc for the server has reached the its maximum. Please, take an action concerning the old logs..\n\n--NextPart"
}
#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | 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 90 ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
aws ses send-raw-email --raw-message file:///home/ubuntu/space-watcher/message.json --region=us-east-1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment