I have the following shell script in place to send out an email alert. When I only have the for loop everything works fine but when I try to add the if condition it does not seem to work and returns a null message body everytime. A snippet from the script is as below:
for host in $servers
do
connections=`ssh $host "netstat -a | grep ES | wc -l"`
echo "$connections" >> debug.log
echo "$host" >> debug.log
if [$connections -gt 0]
then
echo "------------------------------------------------------------------" >> $emailmessage
echo "Host: $host needs to be checked" >> $emailmessage
echo "------------------------------------------------------------------" >> $emailmessage
echo "$connections" >> $emailmessage
else
echo "Everything is fine"
fi
done
I always end up getting the line 21: [49: command not found error when i try to execute the script. I tried debugging but I figured out my script is not even getting inside the if loop.
Can someone please let me know what am I missing?
Thanks in advance.
/rd