
有人可以幫我調試這個簡單的腳本嗎?我已經嘗試了 2 個小時了,但似乎無法讓它發揮作用。
#!/bin/bash
echo "Search for MMSC or WAP connectivity errors"
sftpErrorCount=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" | grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| wc -l)
if [ "$sftpErrorCount" -gt 0 ]
then
sftpErrorDate=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" | grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| tail -1)
echo "Error found at around $sftpErrorDate please check FTP logs"
else
echo "No errors found"
當我執行腳本時出錯:
$ sh test_script.sh
Search for MMSC or WAP connectivity errors
test_script.sh: line 14: syntax error: unexpected end of file
答案1
您需要用單字 來結束 if 語句fi
。
#!/bin/bash
echo "Search for MMSC or WAP connectivity errors"
sftpErrorCount=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" |
grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| wc -l)
if [ "$sftpErrorCount" -gt 0 ] ; then
sftpErrorDate=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" |
grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| tail -1)
echo "Error found at around $sftpErrorDate please check FTP logs"
else
echo "No errors found"
fi
# ^ This closes the block.
另請注意,我對您的腳本進行了一些樣式更改。縮排可以使此類錯誤更容易被發現。