Available disk usage alert setup to run weekly on crontab
This file contains 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/bash | |
# /etc/cron.weekly/ | |
LIMIT="85" | |
MAILTO="" | |
SUBJECT="Disk Usage Alert!" | |
BODY="WARNING! $(hostname) disk space is currently at ${USED}% capacity." | |
# Get usage percentage of root disk space | |
USED=$(df -h | grep "/dev/mapper" | awk '{ print $5 }' | cut -d'%' -f1) | |
# If usage is greater than limit | |
if [ $USED -gt $LIMIT ]; then | |
# Start file reaper in the backgroud | |
bash ~/crontab/retention_reaper > ~/crontab/reaper.log 2>&1 & | |
PSID=$! | |
# Send email alert | |
BODY="WARNING! $(hostname) disk space is currently at ${USED}% capacity. | |
The following directories (older than 15 days) will be removed: | |
$(find /home/sftpuser/*/ftp/* -type d -mtime +15) | |
Process (${PSID}) will remove the directories above in 24 hours unless killed [kill ${PSID}]. | |
" | |
echo -e "$BODY" | mail -s "$SUBJECT" "$MAILTO" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment