To make sure that Tomcat is running all the time, I wrote the following shell script
#!/bin/bash
status="$(curl -s http://www.domain.com/check)"
if [ "$status" != "OK" ]
then
/opt/apache-tomcat-8.0.15/bin/startup.sh
/usr/sbin/sendmail me@domain.com < email.txt
fi
and added it to the crontab via
*/1 * * * * /opt/scripts/check.sh
Now if I shut down the server manually, then I receive an email every minute but for some reason the script won't start Tomcat. However, if I execute check.sh
manually, I receive an email and Tomcat starts running again.
Any ideas as to why adding the script to the crontab does not start Tomcat?
Best Answer
The most likely answer is environment variables, i.e. an interactive shell has a lot (including a rather complete $PATH), whereas for programs run from cron they are typically heavily limited (including an abbreviated path).