Run Apache Tomcat server via cron job and notify an email id

| By Webner

Below is the shell script which can start Apache Tomcat server via cron job and send notification to defined email is:


RESULT=`netstat -na | grep 8009 | awk '{print $7}' | wc -l`
if [ "$RESULT" != 0 ]; then
elif [ "$RESULT" = 0 ]; then
       /opt/lev8/tomcat/bin/ > /dev/null
       echo "Tomcat server have been successfully restarted!" | mail -s "Server Alert: Tomcat restarted"


Note: remove the line numbers before saving it in file.

3rd statements checks if tomcat is already running and prints TOMCAT IS RUNNING if yes otherwise it starts it and sends email.

Now all you have to do is to define the cronjob for above script to execute it every 30 min or so (as required).


*/30 * * * * /myfolder/scripts/

Leave a Reply

Your email address will not be published. Required fields are marked *