Last active
February 28, 2024 01:23
-
-
Save mtcoffee/5c8d877383ba6b52c607763d584c6eac to your computer and use it in GitHub Desktop.
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 | |
#reference - stolen from https://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html | |
#This script should run on any Linux host and has no hard coded parameters | |
#set percentage to trigger alert | |
threshold=80 | |
emailaddress=youremail@yourdomain.com | |
#important****the first line will exclude filesystems with specified strings****** | |
df -PH | grep -vE '^Filesystem|tmpfs|cdrom|nashome' | awk '{ print $5 " " $1 " " $6 }' | while read output; | |
do | |
echo $output | |
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 ) | |
partition=$(echo $output | awk '{ print $2 }' ) | |
mount=$(echo $output | awk '{ print $3 }' ) | |
if [ $usep -ge $threshold ]; then | |
echo -e \ | |
"Running low on space \"$partition ($usep%)\" on $(hostname) as on $(date). " \ | |
"It is mounted at $mount. \n\n " \ | |
"To find large directories in the mount use the disk usage command, i.e. - du -ax $mount | sort -n -r | head -n 10 \n\n " \ | |
"**This email was generated from a script run on $(hostname)**"| \ | |
mailx -s "Alert: Low disk space $usep% on $(hostname)" $emailaddress | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment