Просмотр исходного кода

Merge pull request #373 from raggix/patch-2

handle errors in "grep -c"
Bryan Heden 7 лет назад
Родитель
Сommit
a6c3403314
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      plugins-scripts/check_log.sh

+ 6 - 2
plugins-scripts/check_log.sh

@@ -214,8 +214,12 @@ fi
 
 diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
 
-# Count the number of matching log entries we have
-count=$(egrep -c "$query" "$tempdiff")
+# Count the number of matching log entries we have and handle errors when grep fails
+count=$(grep -c "$query" "$tempdiff" 2>&1)
+if [[ $? -gt 1 ]];then
+    echo "Log check error: $count"
+    exit "$STATE_UNKNOWN"
+fi
 
 # Get the last matching entry in the diff file
 lastentry=$(egrep "$query" "$tempdiff" | tail -1)