我有一个简单的 bash 脚本
#!/bin/bash
Result =$(zgrep -i "blocked session" /BACKUP/server.log.2019-06-23-06.gz | wc -l)
if [[ "$Result" -ge 1 ]];
then
echo "CRITICAL : The error string is found $Result times in server.log file"
exit 2
else
echo "OK: No instances of the error string in the server.log file "
exit 0
fi
wc -l 正确捕获了大约 1744 个错误字符串实例,但未在 if 条件中使用,并且我得到了错误的退出代码
++ zgrep -i "blocked session" /BACKUP/server.log.2019-06-23-06.gz
++ wc -l
+ Result =1744
/tmp/test.sh: line 4: Result: command not found
+ [[ '' -ge 1 ]]
+ echo OK: No instances of the error string in the server.log file '
OK: echo "OK: No instances of the error string in the server.log file
+ exit 0
请让我知道我在这里缺少什么。
答案1
删除第二行的空格:
Result=$(zgrep -i "blocked session" /BACKUP/server.log.2019-06-23-06.gz | wc -l)
代替
Result =$(zgrep -i "blocked session" /BACKUP/server.log.2019-06-23-06.gz | wc -l)