-1

I am trying to write a script to automate my server auditing headaches. I need to check what webserver is running on a server and then find its uptime. But eventhough I am able to find out the webserver I can't compare it with the variable I have saved it to..Here is the part I am having issue with. This is in bash.

Webserver=`curl -Is $(hostname -i) | grep "Server" | awk {'print $2'} | cut -d'/' -f1`

if [ "$Webserver" == "Apache" ]

then
echo "Webserver Apache Uptime: $(/etc/init.d/httpd status | grep "Server uptime")" >> $TEMPFILE

else if [ "$Webserver" == "LiteSpeed" ]

then
echo "Webserver Litespeed: $(head -n4 /tmp/lshttpd/.rtreport | grep UPTIME)" >> $TEMPFILE

else
echo "Unidentified Webserver"

NB: I have the results saved to a temp file in /tmp

ekad
  • 14,436
  • 26
  • 44
  • 46

1 Answers1

0

Your syntax is wrong. You need elif instead of else. Also you're mssing fi at the end of your if statement. Also, for what it's worth, you should wrap $TEMPFILE in double quotes to prevent word splitting for files that contains spaces.

if [[ "$Webserver" == "Apache" ]]; then
  echo "Webserver Apache Uptime: $(/etc/init.d/httpd status | grep "Server uptime")" >> "$TEMPFILE"
elif [ "$Webserver" == "LiteSpeed" ]; then
  echo "Webserver Litespeed: $(head -n4 /tmp/lshttpd/.rtreport | grep UPTIME)" >> "$TEMPFILE"
  echo "Unidentified Webserver"
fi

If you need some good references these are two of my favorite:

Michelle Welcks
  • 3,513
  • 4
  • 21
  • 34
  • Thanks mate...I already fixed it though I just user [[ "$Webserver" == `*`"Apache"`*` ]] and the fi was there I forgot to paste it. The output of the curl command had some space I guess and hence the * helped to match any string rather than an absolute word I guess.. – user3221982 Jan 23 '14 at 03:40