Use shell to automatically execute script files in linux,
The following example is used by myself in the 64-bit Centos6.5 operating system:
I. Copy files regularly
A. Create the tomcatBack. sh file in the/usr/local/wfjb_web_back directory.
File Content:
# Copy the application wfjb_web in tomcat to the/usr/local/wfjb_web_back/tomcat_back/directory and use the date as the file name cp-af/usr/local/apache-tomcat-7.0.73/webapps/ wfjb_web/usr/local/wfjb_web_back/tomcat_back/$ (date-d "today" + "% Y % m % d _ % H % M % S ")/
B. Grant the executable permission to the tomcatBack. sh file.
Chmod-R 777 tomcatBack. sh
C. Create a scheduled task
Add a scheduled task at the end of the/etc/crontab file
0 1 * root/usr/local/wfjb_web_back/tomcatBack. sh # execute tomcatBack. sh every morning.
D. Restart the crontab service to make the newly configured scheduled task take effect.
Service crond restart
Ii. Regular mysql Database Backup
A. Create the backDB. sh file in the/usr/local/wfjb_web_back directory.
File Content:
# Back up the database testDB to the/usr/local/wfjb_web_back/wfjbdb_back/directory and use the date as the file name D =$ (date + % Y % m % d) mysqldump-u root-ptestDB123456 testDB>/usr/local/wfjb_web_back/wfjbdb_back/$ {D }. SQL
B. Grant the executable permission to the backDB. sh file.
Chmod-R 777 backDB. sh
C. Create a scheduled task
Add a scheduled task at the end of the/etc/crontab file
0 2 *** root/usr/local/wfjb_web_back/backDB. sh # Run backDB. sh at every day.
D. Restart the crontab service to make the newly configured scheduled task take effect.
Service crond restart
Iii. crontab scheduled task
Run */5 * every five minutes ****
0 *** per hour ****
Execute 0 0 every day ***
Execute 0 0 every week ** 0
0 0 1 per month **
Execute 0 0 1 1 * every year *