diff options
author | rincewind <rincewind@vulgrim.de> | 2021-07-02 18:01:47 +0200 |
---|---|---|
committer | rincewind <rincewind@vulgrim.de> | 2021-07-02 18:01:47 +0200 |
commit | c2aa1a5fa2dd96c7186704901d33721a63b9cd03 (patch) | |
tree | e1f725ca8274d56c743c27ad93ed175cc2260b5b | |
parent | 14e1d7f6af409c28dab4732357a2b355a1ada85a (diff) | |
download | monitoring-plugins-c2aa1a5fa2dd96c7186704901d33721a63b9cd03.tar.gz |
Add extended and perl regex
-rwxr-xr-x | plugins-scripts/check_log.sh | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 8a79704a..6e9fbca5 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" |