Last active
February 14, 2022 16:34
-
-
Save ehayon/6212309 to your computer and use it in GitHub Desktop.
shell script for monitoring server disk usage
This file contains hidden or 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/sh | |
EXCLUDE=( Filesystem devtmpfs tmpfs ); | |
USAGE_THRESHOLD=85; | |
PREV_IFS=$IFS; # save the old IFS so we can restore it later | |
IFS="|"; # change the internal field separator to a pipe | |
EX="${EXCLUDE[*]}"; # join exclude partitions with pipe separator | |
IFS=$PREV_IFS; # restore IFS | |
df -h | grep -Ev "^${EX}" | awk '{print $5 " " $1}' | while read output; | |
do | |
percentage=$(echo $output | awk '{print $1}' | cut -d'%' -f1) | |
part=$(echo $output | awk '{print $2}') | |
hn=$(hostname) | |
if [ $percentage -gt $USAGE_THRESHOLD ]; then | |
echo "Running out of disk space on partition $part ($percentage%) on server $hn" | | |
mail -s "$hn running out of disk space on $part" <email-address> | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment