Linux simply checking service run scripts

Script reads as follows:

This script meaning: Check whether the service is running, log in to run, and not run the logging service starts

! # / bin / bash      
svrnm = "Tomcat" // Set the name of the service
time = `date` // time
if ps -ef | grep $ svrnm | egrep -v grep> / dev / null // Check if this service is running
the then
echo "$ DATE $ svrnm IS Started!" >> / opt / cklog // information written to the log file will run
the else
echo "$ DATE $ svrnm IS nostart" >> / opt / non-operation is also written cklog // log files
/opt/apache-tomcat-9.0.26/bin/startup.sh >> / opt / cklog // service will run
fi

   Run the script

Use tomcat test

Services during normal operation, run the script

 

Log content

  

  The service is not running, run the script

 

  View Service 

 

Guess you like

Origin www.cnblogs.com/kuiyajia/p/11635467.html