如果我们的服务器上的负载太高,我正在尝试通过脚本向我发送电子邮件通知。我找到了一个好的,但是当我运行它时它给了我和错误,我不明白为什么。
运行下面的代码会出现错误:
第 13 行:意外标记“fi”附近的语法错误
我认为我必须正确布局。谢谢!
#!/bin/bash
THR=10
MAIL="address@domain.com"
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"