Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Available disk usage alert setup to run weekly on crontab
# /etc/cron.weekly/
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 &
# 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment