I'm new in bash scripting, so after writing some code, I'm stuck :) Situation is this: I have few (three) java JARs which are running in the background after system boot. Need to have script which will periodically (10 sec) check if all this JARs are running, even if one of them is not running, it should restart the JAR. Here is my code, please correct it or give better one. This code is working, but there is a little problem: if one of JARs are not working and I running this script, it is starting to run it, but I don't know which one was started. Thus, need to have some universal script, which will understand which process is stopped and restart only it and inform in the screen. Thank you.
#!/bin/bash
vta_oar=`netstat -an | fgrep tcp | fgrep LISTEN | fgrep :8091` #vta-oar 8091
vta_vas=`netstat -an | fgrep tcp | fgrep LISTEN | fgrep :8090` #vta-vas 8090
vta_autokit=`netstat -an | fgrep tcp | fgrep LISTEN | fgrep :8093` #vta_autokit 8093
if [[ -z "$vta_oar" ]] && [[ -z "$vta_vas" ]]
then
echo "Starting Services VTA_OAR/VTA_VAS"
java -jar /var/www/html/vta-oar.jar >> /var/log/vta-oar.log &
java -jar /var/www/html/vta-vas.jar >> /var/log/vta-vas.log &
elif [[ -z "$vta_vas" ]] && [[ -z "$vta_autokit" ]]
then
echo "Starting Services VTA_VAS/VTA_AUTOKIT"
java -jar /var/www/html/vta-vas.jar >> /var/log/vta-vas.log &
java -jar /var/www/html/vta-autokit.jar >> /var/log/vta-autokit.log &
elif [[ -z "$vta_autokit" ]] && [[ -z "$vta_oar" ]]
then
echo "Starting Services VTA_AUTOKIT/VTA_VAS_OAR"
java -jar /var/www/html/vta-autokit.jar >> /var/log/vta-autokit.log &
java -jar /var/www/html/vta-oar.jar >> /var/log/vta-oar.log &
else
echo "All services are running..."
fi