Skip to content

Instantly share code, notes, and snippets.

@johanmeiring
Last active October 2, 2015 02:58
Show Gist options
  • Select an option

  • Save johanmeiring/2157296 to your computer and use it in GitHub Desktop.

Select an option

Save johanmeiring/2157296 to your computer and use it in GitHub Desktop.
Linux disk space checker
#!/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