![조건.변수가 Bash 스크립트에서 처리되지 않은 경우 [닫기]](https://linux55.com/image/156014/%EC%A1%B0%EA%B1%B4.%EB%B3%80%EC%88%98%EA%B0%80%20Bash%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EC%97%90%EC%84%9C%20%EC%B2%98%EB%A6%AC%EB%90%98%EC%A7%80%20%EC%95%8A%EC%9D%80%20%EA%B2%BD%EC%9A%B0%20%5B%EB%8B%AB%EA%B8%B0%5D.png)
간단한 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)