Fix bashism in 40.fs_use
authorMathieu Parent <math.parent@gmail.com>
Wed, 21 Sep 2011 19:49:34 +0000 (21:49 +0200)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 12 Oct 2011 09:08:40 +0000 (20:08 +1100)
Also, add -P to df, to avoid multiline on Linux when device name is long (this is the case with LVM)

config/events.d/40.fs_use

index 14d33fae7458bcd898102a6f9eb567d6941acf0f..abbc17eb1480b2ec054234c0e05f47021bb2e049 100644 (file)
@@ -11,9 +11,8 @@ case "$1" in
         for fs in $CTDB_CHECK_FS_USE
         do
             # parse fs_mount and fs_threshold
-            fs_config=(`echo $fs | tr ':' '\n'`)
-            fs_mount=${fs_config[0])}
-            fs_threshold=${fs_config[1])}
+            fs_mount=`echo "$fs" | awk -F : '{print $1}'`
+            fs_threshold=`echo "$fs" | awk -F : '{print $2}'`
 
             # check if given fs_mount is existing directory
             if [ ! -d "$fs_mount" ]; then
@@ -22,22 +21,22 @@ case "$1" in
             fi
 
             # check if given fs_threshold is number
-            if ! [[ "$fs_threshold" =~ ^[0-9]+$ ]] ; then
+            if ! (echo "$fs_threshold" | egrep -q '^[0-9]+$')  ; then
                 echo "$0: Threshold $fs_threshold is invalid number"
                 exit 1
             fi
 
             # get utilization of given fs from df
-            fs_usage=`df -k $fs_mount | grep % | awk {'print $5'} | sed 's/%//g' | tail -n 1`
+            fs_usage=`df -kP $fs_mount | grep '%' | awk {'print $5'} | sed 's/%//g' | tail -n 1`
 
             # check if fs_usage is number
-            if ! [[ "$fs_usage" =~ ^[0-9]+$ ]] ; then
+            if ! (echo "$fs_usage" | egrep -q '^[0-9]+$') ; then
                 echo "$0: FS utilization $fs_usage is invalid number"
                 exit 1
             fi
 
             # check if fs_usage is higher than or equal to fs_threshold
-            if [[ "$fs_usage" -ge "$fs_threshold" ]] ; then
+            if [ "$fs_usage" -ge "$fs_threshold" ] ; then
                 echo "ERROR: Utilization of $fs_mount ($fs_usage%) is higher than threshold ($fs_threshold%)"
                 exit 1
             fi