Using the shell to automate script files under Linux

Source: Internet
Author: User

The following instance is used in the Centos6.5 64-bit operating system

One, the regular copy file

A. Create the tomcatback.sh file in the/usr/local/wfjb_web_back directory

File contents:

#将tomcat中的应用wfjb_web copied to the/usr/local/wfjb_web_back/tomcat_back/directory and followed by 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. Give executable permissions to the tomcatback.sh file

Chmod-r 777 tomcatback.sh

C. Create a timed task

Add a scheduled task at the end of the/etc/crontab file

0 1 * * * root/usr/local/wfjb_web_back/tomcatback.sh #每天凌晨一点执行tomcatBack. sh This file

D. Finally restart the Crontab service for the newly configured scheduled tasks to take effect

Service Crond Restart

second, scheduled backup MySQL database

A. Create the backdb.sh file in the/usr/local/wfjb_web_back directory

File contents:

#将数据库testDB full backup to the/usr/local/wfjb_web_back/wfjbdb_back/directory and follow 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. Give executable permissions to the backdb.sh file

Chmod-r 777 backdb.sh

C. Create a timed task

Add a scheduled task at the end of the/etc/crontab file

0 2 * * * root/usr/local/wfjb_web_back/backdb.sh #每天凌晨两点执行backDB. sh This file

D. Finally restart the Crontab service for the newly configured scheduled tasks to take effect

Service Crond Restart

Three, crontab scheduled Tasks

Execute */5 every five minutes * * * *

Executes 0 per hour * * * *

Executes 0 0 * * * per day

Weekly Execution 0 0 * 0

Monthly execution 0 0 1 * *

Annual Execution 0 0 1 1 *


Using the shell to automate script files under Linux

Related Article

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.