summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/diskspace.sh
diff options
context:
space:
mode:
authorMichael Hanson <mihanson@linhes.org>2012-04-14 05:13:05 (GMT)
committerMichael Hanson <mihanson@linhes.org>2012-04-14 05:13:05 (GMT)
commit5e96cb93d1f17a98a8f8a118b2659ea4d71d3f43 (patch)
treeacde2ddc972337f648a826f3d961dcb8bebf892a /abs/core/LinHES-system/diskspace.sh
parent8e721470713e6a5a164f1d7682b0d248cb87b03c (diff)
parent502a19b42d9df3fb3c3e521a37eebd20f9fbd984 (diff)
downloadlinhes_pkgbuild-5e96cb93d1f17a98a8f8a118b2659ea4d71d3f43.zip
linhes_pkgbuild-5e96cb93d1f17a98a8f8a118b2659ea4d71d3f43.tar.gz
linhes_pkgbuild-5e96cb93d1f17a98a8f8a118b2659ea4d71d3f43.tar.bz2
Merge branch 'testing' of linhes.org:linhes_pkgbuild into testing
Conflicts: abs/extra/bluez/PKGBUILD abs/extra/bluez/__changelog
Diffstat (limited to 'abs/core/LinHES-system/diskspace.sh')
-rwxr-xr-xabs/core/LinHES-system/diskspace.sh81
1 files changed, 81 insertions, 0 deletions
diff --git a/abs/core/LinHES-system/diskspace.sh b/abs/core/LinHES-system/diskspace.sh
new file mode 100755
index 0000000..2173c6e
--- /dev/null
+++ b/abs/core/LinHES-system/diskspace.sh
@@ -0,0 +1,81 @@
+#!/bin/sh
+### Monitor free disk space
+# Display alert if the free percentage of space is >= $ALERT
+
+#
+# Static Config Variables
+#
+ALERT=90 # free space percentage to trigger an alert
+
+#
+# Static Binary Paths
+#
+DF='/bin/df'
+GREP='/bin/grep'
+AWK='/bin/awk'
+CUT='/bin/cut'
+HOSTNAME='/bin/hostname'
+DATE='/bin/date'
+OSD_CAT='/usr/bin/osd_cat'
+export DISPLAY=:0.0
+#
+# Static System Variables
+#
+THIS_HOST=`${HOSTNAME}`
+
+#
+# Check CLI Options
+#
+VERBOSE=false
+OSD=false
+for ARG in "$@" ; do
+ case $ARG in
+ "-v")
+ VERBOSE=true
+ ;;
+ "-osd")
+ OSD=true
+ ;;
+ esac
+done
+
+#----------------------------------------------------------------------------
+. /etc/osd_cat.cfg || {
+ color=yellow
+ outline=2
+ outlinecolour=black
+ shadow=0
+ shadowcolour=black
+ font="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*"
+}
+#----------------------------------------------------------------------------
+
+[ $VERBOSE = true ] && echo "Checking free disk space on ${THIS_HOST}"
+[ $VERBOSE = true ] && echo "Threshold for warning is ${ALERT}%"
+[ $VERBOSE = true ] && echo "------------------------------------------------------------------"
+
+# Dynamic Variables
+#DATE_STR=`${DATE} "+%d-%B-%y @ %H%Mhrs"`
+
+# Call df to find the used percentages. Grep for only local disks (not remote mounts like nfs or smb)
+# Pipe the output to awk to get the needed columns, then start a while loop to process each line.
+$DF -HPl | $GREP -E "^/dev/" | $AWK '{ print $5 " " $6 " " $1 }' | while read OUTPUT ; do
+ USED_PCENT=$(echo ${OUTPUT} | $AWK '{ print $1}' | $CUT -d'%' -f1 ) # Used space as a percentage
+ PARTITION=$(echo ${OUTPUT} | $AWK '{ print $2 }' ) # Mount Point (eg, /home)
+ DEVICE=$(echo ${OUTPUT} | $AWK '{ print $3 }' ) # Device (eg, /dev/sda1 or LABEL or UUID)
+ if [ $VERBOSE = true ] ; then
+ echo -e "Checking device ${DEVICE} which is mounted to ${PARTITION} \t${USED_PCENT}% used"
+ fi
+ if [ ${USED_PCENT} -ge $ALERT ]; then
+ if [ $VERBOSE = true ] ; then
+ echo "WARNING: ${PARTITION} (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}."
+ else
+ echo "WARNING: ${PARTITION} (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}." #|
+ if [ $OSD = true ] && [ ${PARTITION} = / ]; then
+ echo "WARNING: The root (${PARTITION}) partition is ${USED_PCENT}% full on ${THIS_HOST}." | $OSD_CAT --pos=top --offset=40 --align=center --delay=10 --color=$color --outline=$outline --outlinecolour=$outlinecolour --shadow=$shadow --shadowcolour=$shadowcolour --font=$font &
+ fi
+ fi
+ fi
+done
+
+exit 0