我試圖通過一個腳本來向我發送通知,如果我們的服務器上的負載太高。我找到了一個好的,但是當我運行它時它給了我和錯誤,我看不出爲什麼。Bash腳本錯誤。意外令牌附近的語法錯誤
運行下面的代碼給出了錯誤:
line 13: syntax error near unexpected token `fi'
我想我不得不制定了正確不過。謝謝!
#!/bin/bash
THR=10
MAIL="[email protected]"
VAR=`uptime|awk -F, '{print $4}'|awk '{print $3}'`
OUT=`echo "$VAR $THR" | awk '{if ($1 > $2) print "yes"; else print "no"}'`
if [ "$VAR" == "" ]
then
# it's within the first 24 hours of uptime
VAR=`uptime|awk -F, '{print $3}'|awk '{print $3}'`
OUT=`echo "$VAR $THR" | awk '{if ($1 > $2) print "yes"; else print "no"}'`
fi
if [ "$OUT" == "yes" ]
then
echo "The current load $VAR is greater than the threshold $THR" | mail $MAIL
-s "Server Load Alert"
echo "Alert generated because $VAR is greater than $THR"
else
echo "No alert as $VAR > $THR"
fi
echo "load = $VAR"
用您的shebang行中的標誌-vx執行,並確認錯誤是什麼! '#!/ bin/bash -vx' – Vijay
嗯,空白給了我一個錯誤,所以我刪除了它。現在我得到一個意外的文件結尾 – Adam
嘗試在調試模式下運行它,#/ bin/bash --debug --verbose file.sh –