From c5ef0d1440f1d952784cc67946c414d149722d01 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 14 Oct 2011 15:52:12 +1100 Subject: [PATCH] Eventscripts: Make 40.fs_use use less processes and arguably clearer. * $fs can be parsed using shell prefix and suffix removal. * df output can be parsed with a single call to sed. Failure is indicated by empty output from sed, so we check for that as the error condition, changing the associated message appropriately. Signed-off-by: Martin Schwenke --- config/events.d/40.fs_use | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/events.d/40.fs_use b/config/events.d/40.fs_use index abbc17eb..f678b511 100644 --- a/config/events.d/40.fs_use +++ b/config/events.d/40.fs_use @@ -11,8 +11,8 @@ case "$1" in for fs in $CTDB_CHECK_FS_USE do # parse fs_mount and fs_threshold - fs_mount=`echo "$fs" | awk -F : '{print $1}'` - fs_threshold=`echo "$fs" | awk -F : '{print $2}'` + fs_mount="${fs%:*}" + fs_threshold="${fs#*:}" # check if given fs_mount is existing directory if [ ! -d "$fs_mount" ]; then @@ -27,11 +27,11 @@ case "$1" in fi # get utilization of given fs from df - fs_usage=`df -kP $fs_mount | grep '%' | awk {'print $5'} | sed 's/%//g' | tail -n 1` + fs_usage=$(df -kP $fs_mount | sed -n -e 's@.*[[:space:]]\([[:digit:]]*\)%.*@\1@p') # check if fs_usage is number - if ! (echo "$fs_usage" | egrep -q '^[0-9]+$') ; then - echo "$0: FS utilization $fs_usage is invalid number" + if [ -z "$fs_usage" ] ; then + echo "$0: Unable to get FS utilization for $fs_mount" exit 1 fi -- 2.34.1