Use shell to automatically execute script files in linux,

Source: Internet
Author: User

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 *

 

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.