Last active
October 2, 2015 02:58
-
-
Save johanmeiring/2157296 to your computer and use it in GitHub Desktop.
Linux disk space checker
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/bash | |
| # Disk space checking script. | |
| # Version 0.2 | |
| # All of the below parameters can be overriden via command line arguments. | |
| # Minimum disk space that should be available, in kilobytes. | |
| THRESHOLD=20971520 | |
| # Partition/Filesystem that we should check. | |
| PARTITION="/dev/md1" | |
| # Email address that mail should be sent to. | |
| MAILTO="emailaddress" | |
| # Machine's name. Change to something other than `hostname -f` if you want to. | |
| HOSTNAME="`hostname -f`" | |
| while getopts "t:p:m:H:" OPTION | |
| do | |
| case $OPTION in | |
| t) | |
| THRESHOLD=$OPTARG | |
| ;; | |
| p) | |
| PARTITION="$OPTARG" | |
| ;; | |
| m) | |
| MAILTO="$OPTARG" | |
| ;; | |
| H) | |
| HOSTNAME="$OPTARG" | |
| ;; | |
| esac | |
| done | |
| if [[ "`df | grep "${PARTITION}" | awk '{ print $4 }' | sed -r 's/[A-Z]//g'`" -lt "${THRESHOLD}" ]]; then | |
| (echo "Warning: Filesystem ${PARTITION} on ${HOSTNAME} is below the threshold of ${THRESHOLD}. DO SOMETHING!") | mailx -s "Disk Space on ${HOSTNAME} below ${THRESHOLD}" ${MAILTO} | |
| fi | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment