Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Linux disk space email alert
#!/bin/bash
# www.fduran.com
# script that will send an email to EMAIL when disk use in partition PART is bigger than %MAX
# adapt these 3 parameters to your case
MAX=95
EMAIL=alert@example.com
PART=sda1
USE=`df -h |grep $PART | awk '{ print $5 }' | cut -d'%' -f1`
if [ $USE -gt $MAX ]; then
echo "Percent used: $USE" | mail -s "Running out of disk space" $EMAIL
fi
@ifpingram

This comment has been minimized.

Copy link

commented May 18, 2016

fantastic script - thank you!

@mrforsythexeter

This comment has been minimized.

Copy link

commented Feb 3, 2018

I had to use
df -hP
To get posix format as the $PART was making normal output wrap to a new line.

@fy-kenny

This comment has been minimized.

Copy link

commented Apr 26, 2018

grateful

@onepoint0

This comment has been minimized.

Copy link

commented Jun 12, 2018

Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.