Linux: email alert when disk is nearly full

30/09/2009
#!/bin/bash
# Send an email when disk space used reaches a certain threshold
FS="/"
SERVER_NAME="linux02"
EMAIL="user@example.com"
THRESHOLD=95
OUTPUT=($(LC_ALL=C df -P ${FS}))
CURRENT=$(echo ${OUTPUT[11]} | sed 's/%//')
[ $CURRENT -gt $THRESHOLD ] && df -h | mail -s "$SERVER_NAME disk space alert: $CURRENT% full" $EMAIL

I’ve set this up as a cron job run at 3am daily:

0 3 * * * ./root/maintenance/check_free_space.sh

Based upon http://www.cyberciti.biz/faq/mac-osx-unix-get-an-alert-when-my-disk-is-full/

No comments yet.

Write a comment: