We do frequent deployments using udeploy and we have there a shell script to restart the apache http server as the last task. Script is simple:-
cd bin_path
sudo ./apachectl -k stop
sleep 5
sudo ./apachectl start
while [ $? -ne 0 ]
do
sudo ./apachectl start
sleep 1
done
Now i would like to include an extra condition in this while loop that checks for a certain value of the counter variable, so that attempt to restart the server is restricted to only say 5 times. Now here is what i want.
var = 0
sudo ./apachectl start
while [ $? -ne 0 -o $var lte 5 ]
do
var = $((var+1))
sudo ./apachectl start
sleep 1
done
But somehow i'm not an expert in shell script syntax. If someone can help me correct the script to achieve the desired solution.