"Gadget" shell detects process status exception auto restart

Source: Internet
Author: User

The shell script is an operation of the basic skills of personnel, in peacetime work, in order to deal with some anomalies or query data, I often have to write shell scripts automated processing.

Here to share a script I wrote to detect the status of the process and automatically restart, very simple, welcome to use.

The code is as follows:

#!/bin/bash#filename:tomcatcheck.sh# Feature Description: Detects the number of Tomcat processes, 0, automatically restarts the source ~/.bash_profilenum= ' Ps-aef |grep Tomcat |grep- V grep|wc-l ' echo ' ' date ' check process ' number is $num ' # # # ' date ' output log contains time if ["$num"-eq "0"]; Thenservice Tomcat St Art # # # #重启tomcatelif [$num-gt 1]; Thenecho "' Date ' tomcat ' s process more than 1,is $num" Elseecho "' Date ' Tomcat ' s process working normal! ' Fiexit 0

Set up a scheduled task, check the timing, and output the test results to log.

*/10 * * * */home/user/tomcatcheck.sh >>/home/user/tomcatcheck.log 2>&1


There's a little pit. Note that the NUM result in the above script is a string, and a logical judgment should be made by string when making the If judgment.

"Gadget" shell detects process status exception auto restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.