From c2aa1a5fa2dd96c7186704901d33721a63b9cd03 Mon Sep 17 00:00:00 2001 From: rincewind Date: Fri, 2 Jul 2021 18:01:47 +0200 Subject: Add extended and perl regex diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 8a79704..6e9fbca 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -145,6 +145,22 @@ while test -n "$1"; do exitstatus=$2 shift ;; + --extended-regex) + ERE=1 + shift + ;; + -e) + ERE=1 + shift + ;; + --perl-regex) + PRE=1 + shift + ;; + -p) + PRE=1 + shift + ;; *) echo "Unknown argument: $1" print_usage @@ -154,6 +170,20 @@ while test -n "$1"; do shift done +# Parameter sanity check +if [ $ERE ] && [ $PRE ] ; then + echo "Can not use extended and perl regex at the same time" + exit "$STATE_UNKNOWN" +fi + +if [ $ERE ]; then + GREP="grep -E" +fi + +if [ $PRE ]; then + GREP="grep -P" +fi + # If the source log file doesn't exist, exit if [ ! -e "$logfile" ]; then @@ -190,10 +220,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" -- cgit v0.10-9-g596f