I'm trying to work through a script to email me a notification if the load is too high on our server. I found a good one but it's giving me and error when I run it, and I can't see why.
Running the code below gives the error:
line 13: syntax error near unexpected token `fi'
I thought I had to laid out correctly though. Thanks!
#!/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"
#!/bin/bash -vx