我试图通过一个脚本来向我发送通知,如果我们的服务器上的负载太高。我找到了一个好的,但是当我运行它时它给了我和错误,我看不出为什么。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 –