Set up scripts and steps in Linux to start Tomcat on a timed basis:

Source: Internet
Author: User

1. First write the start and stop Tomcat script, as follows:
-------------------------------------The following is the startup script, but the Tomcat bin path needs to be configured, and the file format in the Linux system is converted to the Linux format. Otherwise the execution will be error-----------------------------------------

Help () {
Cat <This script is primarily used to restart the Web server's tomcat schedule at 11 o'clock every Wednesday night
USAGE example:cmdparser-h or Cmdparser
Exit 0

#帮助信息, describing the script information
While [-N "$"];d o
Case $ in
-h) Help;shift 1;;
--) Shift;break;
-*) echo "Command error you entered"; Exit 1;
*) break;;

Pid= ' ps aux | grep Tomcat | Grep-v grep | Grep-v Retomcat | awk ' {print $} '

Start () {


Stop () {


If [-N "$pid"]
#如果有tomcat进程, you stop Tomcat, then hibernate, and then review the process,
#如果, the process does not exist, then Tomcat is restarted
#tomcat STOP:
# sleeps 5 Seconds
Sleep 5
# Get Tomcat Process
Pid= ' ps aux | grep Tomcat | Grep-v grep | Grep-v Retomcat | awk ' {print $} '
#此时 to see if the Tomcat process exists and if it does, it will be forced to kill the Tomcat process
If [-N "$pid"]
Kill-9 $pid
Sleep 5
#如果没有tomcat进程, Tomcat is started directly

-----------------------------------------execution Script ends---------------------------------------
This script file is then saved and placed in the/root/directory,/root/

2. Editing the task device:
Direct input command crontab-e;
Then edit the content: about the crontab command set execution time, please own Baidu inquires, I here just a little introduction.

I set here to perform at 5 o ' Day every morning:
XX * * *./root/

T1 T2 T3 T4 T5 Program

T1: for the minute
T2: Last
T3: For the day ordinal of the month
T4: for the month
T5: For the day of the week

Various descriptions of T1:
When T1 is *, indicates that every minute is executed
When T1 is a-B, it is executed from the minute of the first
When T1 for */n indicates that every minute interval is performed
When T1 is A,b,c, the first a,b,c minutes are executed.

After editing,: wq! (Save exit)

3. Start the task: service Crond Stop/start

4, if you find that the task does not start the Tomcat, then you can check the task of the message, see if there is an error message:
The mail file is in the/var/spool/mail/root

Set up scripts and steps in Linux to start Tomcat on a timed basis:

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