Linux timed Tasks

Source: Internet
Author: User

A service or software used on a regular basis in Linux to perform command or program tasks in order to meet the requirements for periodic execution of tasks.

The Crond service is a running program, and the crontab command is used to set the timing rules of the command

Crond Service is an important service commonly used in enterprise production. Thousands of servers can use distributed scheduled tasks

All user crontab profiles are stored by default in the/var/spool/cron directory, and the file name is named after the user name.


=======crontab command Operation Syntax =======

crontab [option] [-u user]

Parameter:- R Delete crontab file contents

- E edit crontab file contents

- L View crontab file contents


=======crontab the meaning table of the time period in the syntax format =======

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/82/14/wKiom1dLBJGzsRCMAADHptDc1nA179.png-wh_500x0-wm_3 -wmp_4-s_3189341053.png "title=" 1.png "alt=" Wkiom1dlbjgzsrcmaadhptdc1na179.png-wh_50 "/>


Table of meanings of special symbols in =======crontab syntax format =======


650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/82/13/wKioL1dLBcDBbJ9eAAH5n6KASI0632.png-wh_500x0-wm_3 -wmp_4-s_10750104.png "title=" 2.png "alt=" Wkiol1dlbcdbbj9eaah5n6kasi0632.png-wh_50 "/>


======= Precautions =======

1. Add necessary annotations for timed task rules

2, the command or program is best written in the script to execute

3. Execute the script to use absolute path

4. Add/bin/sh before executing shell Script task

5, scheduled task end plus >/dev/null 2>&1



The role of =======>/dev/null 2>&1 =======

If the timing task specification end does not add >/dev/null 2>&1, there will be a lot of garbage small files stored in the message temporary queue directory, it is easy to cause the hard disk inode space is full, and thus the system services are not normal. The/var/spool/clientmqueue for CentOS 5 is the mail temporary queue directory, and the CentOS 6 system is the Postfix service by default and the directory is/var/spool/postfix/maildrop.



======= timed task instance =======

1./etc/services files are packaged and backed up to/server/backup every 2 hours.

[email protected] scripts]# cat >>services.sh<<eof

> cd/etc/

> tar-zcf/server/backup/services-$ (Date +%f-%h). tar.gz Services

> EOF

[[email protected] scripts] #crontab –e

#services Backup each 2 Hour

XX */2 * * */scripts/services.sh >/del/null 2>&1


====== server time synchronization is performed every 5 minutes =======

[Email protected] scripts]# VI ntp.sh

#!/bin/sh

/usr/sbin/ntpdate ntp1.aliyun.com

[[email protected] scripts] #crontab –e

#time Sync by Xhua 20160529

*/5 * * * */scripts/ntp.sh >/dev/null 2>&1


Linux timed Tasks

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.