I am running my below shell script on a machine on which c++ application server is running on port 8080 and in the shell script I am executing an URL and stores the response coming from that URL in DATA variable.
But suppose if the same app server is down, then it will not be able to execute the URL and then it will print out Retrying Again
and sleep for 30 seconds and then execute the same url again.
#!/bin/bash
HOSTNAME=$hostname
DATA=""
RETRY=15
echo $HOSTNAME
while [ $RETRY -gt 0 ]
do
DATA=$(wget -O - -q -t 1 http://$HOSTNAME:8080/beat)
if [ $? -eq 0 ]
then
break
else
echo "Retrying Again" >&2
# restart the server
let RETRY-=1
sleep 30
fi
done
echo "Server is UP"
And here HOSTNAME
is the local hostname of the server on which I am running my above shell script.
Problem Statement:-
Now what I am trying to do is, if the server is down, then it will print out Retrying Again
so after that I want to check whether port 8080
is opened on $HOSTNAME
or not. If not, then it means server is down so I want to restart the server by executing this command and then sleep for 30 seconds as shown above in the shell script.
/opt/app/test/start_stop.sh start
Is this possible to do here in my above shell script?
I am running this shell script on Ubuntu 12.04.