Crontab (timer) usage in CentOS

Source: Internet
Author: User

about crontab:

The crontab command is commonly used in Unix-and Unix-like operating systems to set instructions that are executed periodically. The command reads the instruction from the standard input device and stores it in a "crontab" file for later reading and execution. The word derives from the Greek language Chronos (χρ?νο), which was originally meant to be time.
Typically, crontab stored instructions are activated by the daemon, Crond often run in the background, checking every minute for scheduled jobs to be executed. This type of work is generally called cron jobs.

Install Crontab:

[[Email protected] ~] # Yum install Vixie-cron[[email protected] ~]# yum install crontabs   

Description
Vixie-cron package is the main program of Cron;
The Crontabs package is a program used to install, uninstall, or list tables used to drive the cron daemon.

Cron is a built-in service for Linux, but it does not automatically get up, and you can start and shut down this service in the following ways:

# # # #Reload the configuration   

View Crontab Service Status:

Service Crond Status

To start the Crontab service manually:

Service Crond Start

Other commands:

#To see if the Crontab service is set to boot, execute the command:ntsysv# join boot automatically: Chkconfig--level 35 Crond on#  list crontab files crontab-l edit crontab file crontab-e # delete crontab file $ crontab- r# recover lost crontab files Span style= "color: #008000;" >##          

log file:/var/log/cron*  

Add:

1. Crontab Related commands

Feature Description: set the timer.

syntax:crontab [-u < user name >][profile] or crontab [-u < user name >][-ELR]

Additional Note:Cron is a resident service that provides the function of a timer that allows the user to execute a preset instruction or program at a specific time. The function of the timer can be used as long as the user edits the timer's configuration file.

configuration file Format: Minute Hour Day Month DayOFWeek Command

Parameters
-e Edit the user's timer settings.
-l lists the user's timer settings.
-R removes the user's timer settings.
-u< User name > Specifies the user name to set the timer.

2. crontab configuration file format

Basic format:
* * * * * command
Time-sharing Weekly command

The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run

Some examples of crontab files:

# 21:30 restarts per night apache30 * * */usr/local/etc/rc.d/lighttpd restart
# 1, 10, 22nd of 4:45 restart APACHE45 4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart
# 1:10 restarts per Saturday, Sunday apache10 1 * * 6,0/usr/local/etc/rc.d/lighttpd restart
# 18:00 to 23:00 every 30 minutes restart apache0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart
# Weekly 11:00AM Restarts APACHE0 * * 6/usr/local/etc/rc.d/lighttpd restart
# from 11 o'clock to 7 in the morning, restart apache* 23-7/1 * * */usr/local/etc/rc.d/lighttpd restart every hour .
# restart every hour apache* */1 * * */usr/local/etc/rc.d/lighttpd restart
# 4th per month with a 11-point restart from Monday to Wednesday apache0 4 * mon-wed/usr/local/etc/rc.d/lighttpd Restart
# January 1 4-point Restart APACHE0 4 1 Jan */usr/local/etc/rc.d/lighttpd restart
# Synchronize time every half hour */30 * * * */usr/sbin/ntpdate 210.72.145.44

3. Other Task scheduling

Cron is configured by default to schedule tasks: hourly, daily, weekly, mouthly, default configuration file is/etc/anacrontab

Put the scripts that need to be executed in the appropriate directory, and the directories are:

/etc/cron.hourly

/etc/cron.daily

/etc/cron.weekly

/ect/cron.mouthly

Reference:

[1] crontab. Baidu Encyclopedia. Http://baike.baidu.com/view/1229061.htm

[2] non-mainstream space. CRONTAB-E usage in CentOS. http://hi.baidu.com/ldbf/blog/item/b4dc9e02f23dcb124bfb51b8.html

[3] brother Bird's Linux private dish. Routine work scheduling (crontab). http://linux.vbird.org/linux_basic/0430cron.php

[4] Dell-richard li.linux cron Scheduling comparison of several implementation methods. Http://zh.community.dell.com/techcenter/f/21/t/1185.aspx

Crontab (timer) usage in CentOS

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.