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

Author - Navneet Kashyap
5.10.2017
|
0 Comments
|

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

#!/bin/sh

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

fi

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).

Example:

*/30 * * * * /myfolder/scripts/tomcat-service.sh

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

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