diff options
author | Jan Wagner <waja@cyconet.org> | 2017-01-06 17:43:22 +0100 |
---|---|---|
committer | Jan Wagner <waja@cyconet.org> | 2017-01-06 17:43:22 +0100 |
commit | 5f3232f00d07dac166b48acd6d0c92ec1ff64901 (patch) | |
tree | e497009ea444f6dabd021ad127b1500d3a8e4dff /plugins-scripts/check_log.sh | |
parent | 439b93049ddcfa28d7d3b8dd8085770c613aabc3 (diff) | |
download | monitoring-plugins-5f3232f00d07dac166b48acd6d0c92ec1ff64901.tar.gz |
Fixing shellcheck SC2086
Diffstat (limited to 'plugins-scripts/check_log.sh')
-rwxr-xr-x | plugins-scripts/check_log.sh | 54 |
1 files changed, 27 insertions, 27 deletions
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" |