Detection of Tomcat by Linux shell script


The Linux shell script detects Tomcat and automatically restarts

Run the command sh XXX in the background sh &
Viewing background tasks: jobs
Summon to the front desk: FG jobs No

You can delete the code of the while loop and put it into crontab for regular execution. You can run the script directly in the background,

while [ true ]
    httpOK=`curl --connect-timeout 10 -m 60 --head --silent $url | awk 'NR==1{print $2}'`;
    if [ $httpOK == "200" ];then
        tomcat6=`ps -ef | grep tomcat | awk 'NR==1{print $1" "$2;}'`;
        user=`echo $tomcat6 | awk 'NR==1{print $1}'`;
        pid=`echo $tomcat6 | awk 'NR==1{print $2}'`;
        if [ $user != "tomcat" ]; then
            service tomcat6 start;
            kill -9 $pid;sleep 5s;service tomcat6 start;service tomcat6 start;service tomcat6 status;
    sleep 5m;

The above is the whole content of this article. I hope you can like it.

Recommended Today

Oracle multi table query intermediate table creation example tutorial

Creation of intermediate table for Oracle multi table query Classification of relationships between tables:   1. One to one (understanding):* e.g. person and ID card* analysis: a person has only one ID card, and one ID card can only correspond to one person  2. One to many (many to one):* e.g. departments and employees* analysis: a department […]