Skip to content

Instantly share code, notes, and snippets.

@aaronzirbes
Last active December 22, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronzirbes/6453699 to your computer and use it in GitHub Desktop.
Save aaronzirbes/6453699 to your computer and use it in GitHub Desktop.
#!/bin/bash
devices=`mount |grep -E '^/dev/' | cut -d ' ' -f 1`
warn_threshold="85"
fail_threshold="90"
status="OK"
for device in ${devices}; do
diskfree=`df -h ${device} |grep ${device}`
percent=`echo ${diskfree} |awk '{print $5}' |sed -e 's/%//'`
free=`echo ${diskfree} |awk '{print $3}' |sed -e 's/%//'`
total=`echo ${diskfree} |awk '{print $4}' |sed -e 's/%//'`
if (( $percent > ${fail_threshold} )); then
echo "FAILURE: ${device} usage is at ${percent}% (${free} free of ${total})"
status="FAILURE"
elif (( $percent > ${warn_threshold} )); then
echo "WARNING: ${device} usage is at ${percent}% (${free} free of ${total})"
if [ "${status}" == "OK" ]; then
status="WARNING"
fi
else
echo "OK: ${device} usage is at ${percent} (${free}% free of ${total})"
fi
done
if [ "${status}" == "OK" ]; then
exit 0
elif [ "${status}" == "WARNING" ]; then
exit 1
elif [ "${status}" == "FAILURE" ]; then
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment