From 439b93049ddcfa28d7d3b8dd8085770c613aabc3 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 16:54:29 +0100 Subject: Fixing shellcheck SC2006 --- plugins-scripts/check_log.sh | 12 ++++---- plugins-scripts/check_oracle.sh | 64 ++++++++++++++++++++-------------------- plugins-scripts/check_sensors.sh | 6 ++-- 3 files changed, 41 insertions(+), 41 deletions(-) (limited to 'plugins-scripts') diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index d28c8d0a..45992687 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -60,8 +60,8 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=`basename $0` -PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +PROGNAME=$(basename $0) +PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" . $PROGPATH/utils.sh @@ -180,9 +180,9 @@ fi # The temporary file that the script should use while # processing the log file. if [ -x /bin/mktemp ]; then - tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX` + tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX) else - tempdiff=`/bin/date '+%H%M%S'` + tempdiff=$(/bin/date '+%H%M%S') tempdiff="/tmp/check_log.${tempdiff}" touch $tempdiff chmod 600 $tempdiff @@ -191,10 +191,10 @@ fi diff $logfile $oldlog | grep -v "^>" > $tempdiff # Count the number of matching log entries we have -count=`grep -c "$query" $tempdiff` +count=$(grep -c "$query" $tempdiff) # Get the last matching entry in the diff file -lastentry=`grep "$query" $tempdiff | tail -1` +lastentry=$(grep "$query" $tempdiff | tail -1) rm -f $tempdiff cat $logfile > $oldlog diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 96078aca..d4d3aae0 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -8,8 +8,8 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=`basename $0` -PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +PROGNAME=$(basename $0) +PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" . $PROGPATH/utils.sh @@ -135,8 +135,8 @@ export ORACLE_HOME PATH LD_LIBRARY_PATH case "$cmd" in --tns) - tnschk=` tnsping $2` - tnschk2=` echo $tnschk | grep -c OK` + tnschk=$(tnsping $2) + tnschk2=$(echo $tnschk | grep -c OK) if [ ${tnschk2} -eq 1 ] ; then tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*} echo "OK - reply time ${tnschk3} from $2" @@ -165,7 +165,7 @@ case "$cmd" in }' ;; --db) - pmonchk=`ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$"` + pmonchk=$(ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$") if [ ${pmonchk} -ge 1 ] ; then echo "${2} OK - ${pmonchk} PMON process(es) running" exit $STATE_OK @@ -181,25 +181,25 @@ case "$cmd" in fi ;; --login) - loginchk=`sqlplus dummy/user@$2 < /dev/null` - loginchk2=` echo $loginchk | grep -c ORA-01017` + loginchk=$(sqlplus dummy/user@$2 < /dev/null) + loginchk2=$(echo $loginchk | grep -c ORA-01017) if [ ${loginchk2} -eq 1 ] ; then echo "OK - dummy login connected" exit $STATE_OK else - loginchk3=` echo "$loginchk" | grep "ORA-" | head -1` + loginchk3=$(echo "$loginchk" | grep "ORA-" | head -1) echo "CRITICAL - $loginchk3" exit $STATE_CRITICAL fi ;; --connect) - connectchk=`sqlplus $2 < /dev/null` - connectchk2=` echo $connectchk | grep -c ORA-` + connectchk=$(sqlplus $2 < /dev/null) + connectchk2=$(echo $connectchk | grep -c ORA-) if [ ${connectchk2} -eq 0 ] ; then echo "OK - login successful" exit $STATE_OK else - connectchk3=` echo "$connectchk" | grep "ORA-" | head -1` + connectchk3=$(echo "$connectchk" | grep "ORA-" | head -1) echo "CRITICAL - $connectchk3" exit $STATE_CRITICAL fi @@ -219,29 +219,29 @@ and dbg.name='db block gets' and cg.name='consistent gets'; EOF` - if [ -n "`echo $result | grep ORA-`" ] ; then - error=` echo "$result" | grep "ORA-" | head -1` - echo "CRITICAL - $error" - exit $STATE_CRITICAL + if [ -n "$(echo $result | grep ORA-)" ] ; then + error=$(echo "$result" | grep "ORA-" | head -1) + echo "CRITICAL - $error" + exit $STATE_CRITICAL fi - buf_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'` - buf_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` + buf_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') + buf_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') result=`sqlplus -s ${3}/${4}@${2} << EOF set pagesize 0 set numf '9999999.99' select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 from v\\$librarycache lc; EOF` - - if [ -n "`echo $result | grep ORA-`" ] ; then - error=` echo "$result" | grep "ORA-" | head -1` - echo "CRITICAL - $error" - exit $STATE_CRITICAL + + if [ -n "$(echo $result | grep ORA-)" ] ; then + error=$(echo "$result" | grep "ORA-" | head -1) + echo "CRITICAL - $error" + exit $STATE_CRITICAL fi - lib_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'` - lib_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` + lib_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') + lib_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" @@ -273,16 +273,16 @@ from dba_free_space group by tablespace_name) B ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; EOF` - if [ -n "`echo $result | grep ORA-`" ] ; then - error=` echo "$result" | grep "ORA-" | head -1` - echo "CRITICAL - $error" - exit $STATE_CRITICAL + if [ -n "$(echo $result | grep ORA-)" ] ; then + error=$(echo "$result" | grep "ORA-" | head -1) + echo "CRITICAL - $error" + exit $STATE_CRITICAL fi - ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'` - ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'` - ts_pct=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'` - ts_pctx=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'` + ts_free=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}') + ts_total=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}') + ts_pct=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}') + ts_pctx=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}') if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then echo "No data returned by Oracle - tablespace $5 not found?" exit $STATE_UNKNOWN diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh index f7428301..5348b175 100755 --- a/plugins-scripts/check_sensors.sh +++ b/plugins-scripts/check_sensors.sh @@ -2,8 +2,8 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=`basename $0` -PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +PROGNAME=$(basename $0) +PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" . $PROGPATH/utils.sh @@ -41,7 +41,7 @@ case "$1" in exit $STATE_OK ;; *) - sensordata=`sensors 2>&1` + sensordata=$(sensors 2>&1) status=$? if test ${status} -eq 127; then text="SENSORS UNKNOWN - command not found (did you install lmsensors?)" -- cgit v1.2.3 From 5f3232f00d07dac166b48acd6d0c92ec1ff64901 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 17:43:22 +0100 Subject: Fixing shellcheck SC2086 --- plugins-scripts/check_log.sh | 54 +++++----- plugins-scripts/check_oracle.sh | 206 +++++++++++++++++++-------------------- plugins-scripts/check_sensors.sh | 30 +++--- 3 files changed, 145 insertions(+), 145 deletions(-) (limited to 'plugins-scripts') diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 45992687..8f76b1b5 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -60,11 +60,11 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=$(basename $0) -PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') +PROGNAME=$(basename "$0") +PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" -. $PROGPATH/utils.sh +. "$PROGPATH"/utils.sh print_usage() { echo "Usage: $PROGNAME -F logfile -O oldlog -q query" @@ -73,7 +73,7 @@ print_usage() { } print_help() { - print_revision $PROGNAME $REVISION + print_revision "$PROGNAME" "$REVISION" echo "" print_usage echo "" @@ -87,7 +87,7 @@ print_help() { if [ $# -lt 1 ]; then print_usage - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" fi # Grab the command line arguments @@ -100,19 +100,19 @@ while test -n "$1"; do case "$1" in --help) print_help - exit $STATE_OK + exit "$STATE_OK" ;; -h) print_help - exit $STATE_OK + exit "$STATE_OK" ;; --version) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; -V) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; --filename) logfile=$2 @@ -149,7 +149,7 @@ while test -n "$1"; do *) echo "Unknown argument: $1" print_usage - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" ;; esac shift @@ -157,22 +157,22 @@ done # If the source log file doesn't exist, exit -if [ ! -e $logfile ]; then +if [ ! -e "$logfile" ]; then echo "Log check error: Log file $logfile does not exist!" - exit $STATE_UNKNOWN -elif [ ! -r $logfile ] ; then + exit "$STATE_UNKNOWN" +elif [ ! -r "$logfile" ] ; then echo "Log check error: Log file $logfile is not readable!" - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" fi # If the old log file doesn't exist, this must be the first time # we're running this test, so copy the original log file over to # the old diff file and exit -if [ ! -e $oldlog ]; then - cat $logfile > $oldlog +if [ ! -e "$oldlog" ]; then + cat "$logfile" > "$oldlog" echo "Log check data initialized..." - exit $STATE_OK + exit "$STATE_OK" fi # The old log file exists, so compare it to the original log now @@ -184,20 +184,20 @@ if [ -x /bin/mktemp ]; then else tempdiff=$(/bin/date '+%H%M%S') tempdiff="/tmp/check_log.${tempdiff}" - touch $tempdiff - chmod 600 $tempdiff + touch "$tempdiff" + chmod 600 "$tempdiff" fi -diff $logfile $oldlog | grep -v "^>" > $tempdiff +diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" # Count the number of matching log entries we have -count=$(grep -c "$query" $tempdiff) +count=$(grep -c "$query" "$tempdiff") # Get the last matching entry in the diff file -lastentry=$(grep "$query" $tempdiff | tail -1) +lastentry=$(grep "$query" "$tempdiff" | tail -1) -rm -f $tempdiff -cat $logfile > $oldlog +rm -f "$tempdiff" +cat "$logfile" > "$oldlog" if [ "$count" = "0" ]; then # no matches, exit with no error echo "Log check ok - 0 pattern matches found" @@ -207,4 +207,4 @@ else # Print total matche count and the last entry we found exitstatus=$STATE_CRITICAL fi -exit $exitstatus +exit "$exitstatus" diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index d4d3aae0..0e751f3f 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -8,11 +8,11 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=$(basename $0) -PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') +PROGNAME=$(basename "$0") +PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" -. $PROGPATH/utils.sh +. "$PROGPATH"/utils.sh print_usage() { @@ -29,7 +29,7 @@ print_usage() { } print_help() { - print_revision $PROGNAME $REVISION + print_revision "$PROGNAME" "$REVISION" echo "" print_usage echo "" @@ -87,47 +87,47 @@ esac case "$cmd" in --help) print_help - exit $STATE_OK + exit "$STATE_OK" ;; -h) print_help - exit $STATE_OK + exit "$STATE_OK" ;; --version) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; -V) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; esac # Hunt down a reasonable ORACLE_HOME if [ -z "$ORACLE_HOME" ] ; then - # Adjust to taste - for oratab in /var/opt/oracle/oratab /etc/oratab - do - [ ! -f $oratab ] && continue - ORACLE_HOME=`IFS=: - while read SID ORACLE_HOME junk; - do - if [ "$SID" = "$2" -o "$SID" = "*" ] ; then - echo $ORACLE_HOME; - exit; - fi; - done < $oratab` - [ -n "$ORACLE_HOME" ] && break - done + # Adjust to taste + for oratab in /var/opt/oracle/oratab /etc/oratab + do + [ ! -f $oratab ] && continue + ORACLE_HOME=`IFS=: + while read SID ORACLE_HOME junk; + do + if [ "$SID" = "$2" -o "$SID" = "*" ] ; then + echo "$ORACLE_HOME"; + exit; + fi; + done < $oratab` + [ -n "$ORACLE_HOME" ] && break + done fi # Last resort -[ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] && ORACLE_HOME=$PROGPATH/oracle +[ -z "$ORACLE_HOME" -a -d "$PROGPATH"/oracle ] && ORACLE_HOME=$PROGPATH/oracle if [ "$cmd" != "--db" ]; then - if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then - echo "Cannot determine ORACLE_HOME for sid $2" - exit $STATE_UNKNOWN - fi + if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then + echo "Cannot determine ORACLE_HOME for sid $2" + exit "$STATE_UNKNOWN" + fi fi PATH=$PATH:$ORACLE_HOME/bin LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib @@ -135,81 +135,81 @@ export ORACLE_HOME PATH LD_LIBRARY_PATH case "$cmd" in --tns) - tnschk=$(tnsping $2) - tnschk2=$(echo $tnschk | grep -c OK) - if [ ${tnschk2} -eq 1 ] ; then - tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*} - echo "OK - reply time ${tnschk3} from $2" - exit $STATE_OK + tnschk=$(tnsping "$2") + tnschk2=$(echo "$tnschk" | grep -c OK) + if [ "${tnschk2}" -eq 1 ] ; then + tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*} + echo "OK - reply time ${tnschk3} from $2" + exit "$STATE_OK" else - echo "No TNS Listener on $2" - exit $STATE_CRITICAL + echo "No TNS Listener on $2" + exit "$STATE_CRITICAL" fi ;; --oranames) - namesctl status $2 | awk ' + namesctl status "$2" | awk ' /Server has been running for:/ { - msg = "OK: Up" - for (i = 6; i <= NF; i++) { - msg = msg " " $i - } - status = '$STATE_OK' + msg = "OK: Up" + for (i = 6; i <= NF; i++) { + msg = msg " " $i + } + status = '"$STATE_OK"' } /error/ { - msg = "CRITICAL: " $0 - status = '$STATE_CRITICAL' + msg = "CRITICAL: " $0 + status = '"$STATE_CRITICAL"' } END { - print msg - exit status + print msg + exit status }' ;; --db) pmonchk=$(ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$") - if [ ${pmonchk} -ge 1 ] ; then - echo "${2} OK - ${pmonchk} PMON process(es) running" - exit $STATE_OK + if [ "${pmonchk}" -ge 1 ] ; then + echo "${2} OK - ${pmonchk} PMON process(es) running" + exit "$STATE_OK" #if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then - #if [ ${pmonchk} -eq 1 ] ; then + #if [ ${pmonchk} -eq 1 ] ; then #utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55` - #echo "${2} OK - running since ${utime}" - #exit $STATE_OK - #fi + #echo "${2} OK - running since ${utime}" + #exit $STATE_OK + #fi else - echo "${2} Database is DOWN" - exit $STATE_CRITICAL + echo "${2} Database is DOWN" + exit "$STATE_CRITICAL" fi ;; --login) - loginchk=$(sqlplus dummy/user@$2 < /dev/null) - loginchk2=$(echo $loginchk | grep -c ORA-01017) - if [ ${loginchk2} -eq 1 ] ; then - echo "OK - dummy login connected" - exit $STATE_OK + loginchk=$(sqlplus dummy/user@"$2" < /dev/null) + loginchk2=$(echo "$loginchk" | grep -c ORA-01017) + if [ "${loginchk2}" -eq 1 ] ; then + echo "OK - dummy login connected" + exit "$STATE_OK" else - loginchk3=$(echo "$loginchk" | grep "ORA-" | head -1) - echo "CRITICAL - $loginchk3" - exit $STATE_CRITICAL + loginchk3=$(echo "$loginchk" | grep "ORA-" | head -1) + echo "CRITICAL - $loginchk3" + exit "$STATE_CRITICAL" fi ;; --connect) - connectchk=$(sqlplus $2 < /dev/null) - connectchk2=$(echo $connectchk | grep -c ORA-) - if [ ${connectchk2} -eq 0 ] ; then - echo "OK - login successful" - exit $STATE_OK + connectchk=$(sqlplus "$2" < /dev/null) + connectchk2=$(echo "$connectchk" | grep -c ORA-) + if [ "${connectchk2}" -eq 0 ] ; then + echo "OK - login successful" + exit "$STATE_OK" else - connectchk3=$(echo "$connectchk" | grep "ORA-" | head -1) - echo "CRITICAL - $connectchk3" - exit $STATE_CRITICAL + connectchk3=$(echo "$connectchk" | grep "ORA-" | head -1) + echo "CRITICAL - $connectchk3" + exit "$STATE_CRITICAL" fi ;; --cache) - if [ ${5} -gt ${6} ] ; then - echo "UNKNOWN - Warning level is less then Crit" - exit $STATE_UNKNOWN + if [ "${5}" -gt "${6}" ] ; then + echo "UNKNOWN - Warning level is less then Crit" + exit "$STATE_UNKNOWN" fi - result=`sqlplus -s ${3}/${4}@${2} << EOF + result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF set pagesize 0 set numf '9999999.99' select (1-(pr.value/(dbg.value+cg.value)))*100 @@ -219,48 +219,48 @@ and dbg.name='db block gets' and cg.name='consistent gets'; EOF` - if [ -n "$(echo $result | grep ORA-)" ] ; then + if [ -n "$(echo "$result" | grep ORA-)" ] ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" - exit $STATE_CRITICAL + exit "$STATE_CRITICAL" fi buf_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') buf_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') - result=`sqlplus -s ${3}/${4}@${2} << EOF + result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF set pagesize 0 set numf '9999999.99' select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 from v\\$librarycache lc; EOF` - if [ -n "$(echo $result | grep ORA-)" ] ; then + if [ -n "$(echo "$result" | grep ORA-)" ] ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" - exit $STATE_CRITICAL + exit "$STATE_CRITICAL" fi lib_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') lib_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') - if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then - echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" - exit $STATE_CRITICAL + if [ "$buf_hr" -le "${5}" -o "$lib_hr" -le "${5}" ] ; then + echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" + exit "$STATE_CRITICAL" fi - if [ $buf_hr -le ${6} -o $lib_hr -le ${6} ] ; then - echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" - exit $STATE_WARNING + if [ "$buf_hr" -le "${6}" -o "$lib_hr" -le "${6}" ] ; then + echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" + exit "$STATE_WARNING" fi echo "${2} OK - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" - exit $STATE_OK + exit "$STATE_OK" ;; --tablespace) - if [ ${6} -lt ${7} ] ; then - echo "UNKNOWN - Warning level is more then Crit" - exit $STATE_UNKNOWN + if [ "${6}" -lt "${7}" ] ; then + echo "UNKNOWN - Warning level is more then Crit" + exit "$STATE_UNKNOWN" fi - result=`sqlplus -s ${3}/${4}@${2} << EOF + result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF set pagesize 0 set numf '9999999.99' select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc @@ -273,10 +273,10 @@ from dba_free_space group by tablespace_name) B ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; EOF` - if [ -n "$(echo $result | grep ORA-)" ] ; then + if [ -n "$(echo "$result" | grep ORA-)" ] ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" - exit $STATE_CRITICAL + exit "$STATE_CRITICAL" fi ts_free=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}') @@ -285,20 +285,20 @@ EOF` ts_pctx=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}') if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then echo "No data returned by Oracle - tablespace $5 not found?" - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" fi - if [ "$ts_pct" -ge ${6} ] ; then - echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" - exit $STATE_CRITICAL + if [ "$ts_pct" -ge "${6}" ] ; then + echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" + exit "$STATE_CRITICAL" fi - if [ "$ts_pct" -ge ${7} ] ; then - echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" - exit $STATE_WARNING + if [ "$ts_pct" -ge "${7}" ] ; then + echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" + exit "$STATE_WARNING" fi echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" - exit $STATE_OK + exit "$STATE_OK" ;; *) print_usage - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" esac diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh index 5348b175..9a6cf5de 100755 --- a/plugins-scripts/check_sensors.sh +++ b/plugins-scripts/check_sensors.sh @@ -2,43 +2,43 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=$(basename $0) -PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') +PROGNAME=$(basename "$0") +PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" -. $PROGPATH/utils.sh +. "$PROGPATH"/utils.sh print_usage() { echo "Usage: $PROGNAME" [--ignore-fault] } print_help() { - print_revision $PROGNAME $REVISION + print_revision "$PROGNAME" "$REVISION" echo "" print_usage echo "" echo "This plugin checks hardware status using the lm_sensors package." echo "" support - exit $STATE_OK + exit "$STATE_OK" } case "$1" in --help) print_help - exit $STATE_OK + exit "$STATE_OK" ;; -h) print_help - exit $STATE_OK + exit "$STATE_OK" ;; --version) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; -V) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; *) sensordata=$(sensors 2>&1) @@ -49,10 +49,10 @@ case "$1" in elif test ${status} -ne 0; then text="WARNING - sensors returned state $status" exit=$STATE_WARNING - elif echo ${sensordata} | egrep ALARM > /dev/null; then + elif echo "${sensordata}" | egrep ALARM > /dev/null; then text="SENSOR CRITICAL - Sensor alarm detected!" exit=$STATE_CRITICAL - elif echo ${sensordata} | egrep FAULT > /dev/null \ + elif echo "${sensordata}" | egrep FAULT > /dev/null \ && test "$1" != "-i" -a "$1" != "--ignore-fault"; then text="SENSOR UNKNOWN - Sensor reported fault" exit=$STATE_UNKNOWN @@ -63,8 +63,8 @@ case "$1" in echo "$text" if test "$1" = "-v" -o "$1" = "--verbose"; then - echo ${sensordata} + echo "${sensordata}" fi - exit $exit + exit "$exit" ;; esac -- cgit v1.2.3 From 1204d7fe56c9f35af6500f5ddbae733a622fb63d Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 17:56:03 +0100 Subject: Fixing shellcheck SC2009 This requires pgrep from the procps package. --- plugins-scripts/check_oracle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins-scripts') diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 0e751f3f..70a3fefa 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -165,7 +165,7 @@ case "$cmd" in }' ;; --db) - pmonchk=$(ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$") + pmonchk=$(pgrep -f "(asm|ora)_pmon_${2}$") if [ "${pmonchk}" -ge 1 ] ; then echo "${2} OK - ${pmonchk} PMON process(es) running" exit "$STATE_OK" -- cgit v1.2.3 From 5c473c8612a55cc71689bf4ba468a464bf9da197 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 18:02:36 +0100 Subject: Fixing shellcheck SC2143 --- plugins-scripts/check_oracle.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins-scripts') diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 70a3fefa..9b9540a6 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -219,7 +219,7 @@ and dbg.name='db block gets' and cg.name='consistent gets'; EOF` - if [ -n "$(echo "$result" | grep ORA-)" ] ; then + if echo "$result" | grep -q 'ORA-' ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" exit "$STATE_CRITICAL" @@ -234,7 +234,7 @@ select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 from v\\$librarycache lc; EOF` - if [ -n "$(echo "$result" | grep ORA-)" ] ; then + if echo "$result" | grep -q 'ORA-' ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" exit "$STATE_CRITICAL" @@ -273,7 +273,7 @@ from dba_free_space group by tablespace_name) B ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; EOF` - if [ -n "$(echo "$result" | grep ORA-)" ] ; then + if echo "$result" | grep -q 'ORA-' ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" exit "$STATE_CRITICAL" -- cgit v1.2.3 From 9d8e973b93f261cbb52f5cb944f2e074c348290d Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 18:14:55 +0100 Subject: Fixing shellcheck SC2162 --- plugins-scripts/check_oracle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins-scripts') diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 9b9540a6..bfd9e8f0 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -110,7 +110,7 @@ if [ -z "$ORACLE_HOME" ] ; then do [ ! -f $oratab ] && continue ORACLE_HOME=`IFS=: - while read SID ORACLE_HOME junk; + while read -r SID ORACLE_HOME junk; do if [ "$SID" = "$2" -o "$SID" = "*" ] ; then echo "$ORACLE_HOME"; -- cgit v1.2.3 From 8294af907bd8482a86df749f562b7ec09e3faeed Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 18:39:51 +0100 Subject: Fixing shellcheck SC2166 --- plugins-scripts/check_oracle.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins-scripts') diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index bfd9e8f0..b14ec50e 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -112,7 +112,7 @@ if [ -z "$ORACLE_HOME" ] ; then ORACLE_HOME=`IFS=: while read -r SID ORACLE_HOME junk; do - if [ "$SID" = "$2" -o "$SID" = "*" ] ; then + if [ "$SID" = "$2" ] || [ "$SID" = "*" ] ; then echo "$ORACLE_HOME"; exit; fi; @@ -121,10 +121,10 @@ if [ -z "$ORACLE_HOME" ] ; then done fi # Last resort -[ -z "$ORACLE_HOME" -a -d "$PROGPATH"/oracle ] && ORACLE_HOME=$PROGPATH/oracle +[ -z "$ORACLE_HOME" ] && [ -d "$PROGPATH"/oracle ] && ORACLE_HOME=$PROGPATH/oracle if [ "$cmd" != "--db" ]; then - if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then + if [ -z "$ORACLE_HOME" ] || [ ! -d "$ORACLE_HOME" ] ; then echo "Cannot determine ORACLE_HOME for sid $2" exit "$STATE_UNKNOWN" fi @@ -243,11 +243,11 @@ EOF` lib_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') lib_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') - if [ "$buf_hr" -le "${5}" -o "$lib_hr" -le "${5}" ] ; then + if [ "$buf_hr" -le "${5}" ] || [ "$lib_hr" -le "${5}" ] ; then echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" exit "$STATE_CRITICAL" fi - if [ "$buf_hr" -le "${6}" -o "$lib_hr" -le "${6}" ] ; then + if [ "$buf_hr" -le "${6}" ] || [ "$lib_hr" -le "${6}" ] ; then echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" exit "$STATE_WARNING" fi @@ -283,7 +283,7 @@ EOF` ts_total=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}') ts_pct=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}') ts_pctx=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}') - if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then + if [ "$ts_free" -eq 0 ] && [ "$ts_total" -eq 0 ] && [ "$ts_pct" -eq 0 ] ; then echo "No data returned by Oracle - tablespace $5 not found?" exit "$STATE_UNKNOWN" fi -- cgit v1.2.3