Im trying to get the server to email me if the load goes above 15, but i keep getting the following error.
如果负载超过15,我试图让服务器给我发邮件,但是我一直有以下错误。
root@echo [~]# sh load.sh load.sh: line 9: syntax error near unexpected token `fi' load.sh: line 9: `fi'
Here is the load.sh
这是load.sh
#!/bin/bash
SUBJECT="`hostname`server load is high"
TO=myemail@gmail.com
uptime > /tmp/load
if [ `uptime | awk '{ print$11 }' | cut -d. -f1` -gt 1 ];
then
mail -s "$SUBJECT" $TO < /tmp/load
exit
fi
Server uname -a
服务器uname -
Linux 2.6.18-308.24.1.el5 #1 SMP Tue Dec 4 17:43:34 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
Linux 2.6.18-308.24.1。el5 #1 SMP Tue 12月4日17:43:34 x86_64 x86_64 x86_64 GNU/Linux。
1 个解决方案
#1
0
I don't really get the same error than you but you can already test this solution:
我没有得到和你一样的错误但是你已经可以测试这个解了
if [ `uptime | awk '{ print$11 }' | cut -d. -f1` -gt 1 ];
This condition try to compare a float with an integer. I would make this test with an extended test command. And you can forget semicolon if you don't put then
keyword on the same line than your condition :
此条件尝试将浮点数与整数进行比较。我将通过一个扩展的测试命令来进行这个测试。你可以忘记分号如果你不把关键字放在同一行上
if [[ `uptime | awk '{ print$11 }' | cut -d. -f1` > 1 ]]
then
mail -s "$SUBJECT" $TO < /tmp/load
exit
fi
#1
0
I don't really get the same error than you but you can already test this solution:
我没有得到和你一样的错误但是你已经可以测试这个解了
if [ `uptime | awk '{ print$11 }' | cut -d. -f1` -gt 1 ];
This condition try to compare a float with an integer. I would make this test with an extended test command. And you can forget semicolon if you don't put then
keyword on the same line than your condition :
此条件尝试将浮点数与整数进行比较。我将通过一个扩展的测试命令来进行这个测试。你可以忘记分号如果你不把关键字放在同一行上
if [[ `uptime | awk '{ print$11 }' | cut -d. -f1` > 1 ]]
then
mail -s "$SUBJECT" $TO < /tmp/load
exit
fi