1: Check the status of the Crond service (confirm that the Linux Task Scheduler service is turned on)
Service Crond Status
Crond (PID 1937) is running ...
2: Write the SH executable file that restarts Tomcat restart_tomcat.sh
#!/bin/sh
#./etc/profile
Export java_home=/usr/java/jdk1.8.0_112
sh/opt/apache-tomcat-9.0.0.m11/bin/shutdown.sh
Sleep 60s
sh/opt/apache-tomcat-9.0.0.m11/bin/startup.sh
3: Manually test whether the file can be executed
[Email protected] bin]#./restart_tomcat.sh
-bash:./restart_tomcat.sh:/bin/sh^m:bad interpreter:no such file or directory
The above error is because restart_tomcat.sh is created directly under the window system and needs to be modified in the format of the file.
For the Linux system format, execute the following command in turn:
---------------------------------------------------------------------------------------------------------
Assigning Permissions to Files
chmod 777 restart_tomcat.sh
then modify the file format
VI restart_tomcat.sh
use the following command to view the file format
: Set FF or: Set FileFormat
You can see the following information
Fileformat=dos or Fileformat=unix
use the following command to modify the file format
: Set Ff=unix or: Set Fileformat=unix
Save exit
: Wq
After performing the above operation, perform the discovery execution OK again
[Email protected] bin]#./restart_tomcat.sh
Using catalina_base:/opt/apache-tomcat-9.0.0.m11
Using Catalina_home:/opt/apache-tomcat-9.0.0.m11
Using Catalina_tmpdir:/opt/apache-tomcat-9.0.0.m11/temp
Using Jre_home:/usr/java/jdk1.8.0_112
Using CLASSPATH:/opt/apache-tomcat-9.0.0.m11/bin/bootstrap.jar:/opt/apache-tomcat-9.0.0.m11/bin/tomcat-juli.jar
Using catalina_base:/opt/apache-tomcat-9.0.0.m11
Using Catalina_home:/opt/apache-tomcat-9.0.0.m11
Using catalina_tmpdir:/opt/apache-tomcat-9.0.0.m11/temp
Using Jre_home:/usr/java/jdk1.8.0_112
Using CLASSPATH:/opt/apache-tomcat-9.0.0.m11/bin/bootstrap.jar:/opt/apache-tomcat-9.0.0.m11/bin/tomcat-juli.jar
Tomcat started.
4: Add crontab Task Scheduler
[Email protected] bin]# CRONTAB-E
0 1 * * */opt/apache-tomcat-9.0.0.m11/bin/restart_tomcat.sh
Execute the restart_tomcat.sh file under the specified path every 1 o'clock in the morning
Linux restarts the Tomcat service on a regular basis