crontab Timer Installation and Usage

Common crontab command Unix and Linux the operating system among the provided instructions to be executed periodically. The command instructions read from the standard input device, and store it in the "crontab" file for read and executed later. Typically, the instructions are stored crontab daemon activated. crond often runs in the background every minute to check for scheduled jobs need to be performed. Such work is generally known as cron jobs.

 

First, install

[root@CentOS ~]# yum -y install vixie-cron
[root@CentOS ~]# yum -y install crontabs

Description:
vixie-cron cron package is the main program;
crontabs package is used to install, uninstall, or list the program used to drive the cron daemon table.

Second, the configuration

cron is a linux built-in services, but it does not auto-up, you can start with the following methods to close this service:
Service // Start to start the service crond
service crond stop // close the service
service crond restart // restart the service
service crond reload // reload the configuration
service crond status // Check service status crontab

Add boot CentOS system automatically starts: chkconfig --level 345 crond on

cron main configuration file is  / etc / the crontab , comprising the following lines:

the SHELL = / bin / the bash
the PATH = / sbin: / bin: / usr / sbin: / usr / bin
a MAILTO = the root
the HOME = /

# RUN-Parts
* * * * the root 01 RUN-Parts /etc/cron.hourly
02. 4-RUN * * * Parts /etc/cron.daily the root
22 is the root. 4 0 * * Parts /etc/cron.weekly RUN-
42 is. 4. 1 * * root run-parts /etc/cron.monthly

first four lines are variables used to configure the cron task operating environment.
SHELL variable value tells the system which shell environment to use (in this case shell is bash);
the PATH variable defines the path used to execute commands.
the output of cron task is mailed to the user name MAILTO variable is defined.
If the MAILTO variable is defined as an empty string (MAILTO = ""), email will not be sent.
HOME variable can be used to set the home directory to use when executing commands or scripts.

 

Restrictions on the use of cron:

/etc/cron.allow
and /etc/cron.deny  files are used to restrict the use of cron.
Both formats use the control file is one user per line.
Both files are no spaces.
If a control file has been modified, cron daemon (crond) does not have to be restarted.
The access control files are read each time a user to add or delete a cron task.

Whatever the requirement to use the control file, root can always use cron.

If cron.allow file exists, only users listed in it are allowed to use cron, and cron.deny file will be ignored.
If cron.allow file does not exist, all users listed in cron.deny are forbidden to use cron.

 

Three, crontab command

Function : Set the timer.

Syntax : crontab [-u <user name>] [Profile] or crontab [-u <user name>] [- elr]
explained : cron is a permanent service, which provides a timer function, allowing users to specific time to execute preset commands or programs. As long as a user can edit the timer configuration file, you can use the timer function. Its configuration file format is as follows: Minute Hour Day Month DayOFWeek Command

parameters:
-e edit the user timer setting.
-l lists the user's timer settings.
-r Remove the user timer settings.
-u <user name> Specifies the user name you want to set the timer.

 

Format:
* * * * * Command
sharing command periphery moon and

the first column represents 1 minute to 59 * with *, or / minute per 1 indicates
the second column shows the hours 1 to 23 (0 represents 0:00)
the third column indicates 1 to 31
of 4 February 1 to 12 represent
the first five weeks of the identification number from 0 to 6 (0 = Sunday)
in column 6 of the command to run

 

Examples:
* / 5 * * * * root ab -n 2000 http://60.217.229.252/250k.jpg

The above example shows simulated user access every five minutes http://60.217.229.252/250k.jpg 2000 times

 

30 21 * * * /usr/local/etc/rc.d/lighttpd restart
the example above indicates night 21:30 restart apache.

45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
the above example is 1, 10, 422 days per month: 45 restart apache.

10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
the above examples represent every Saturday, Sunday 1: 10 to restart apache.

0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
the above example are shown in day 18: 00-23: 00 every 30 minutes to restart apache.

0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
the above examples represent every Saturday in 11: 00 pm restart apache.

* * / 1 * * * /usr/local/etc/rc.d/lighttpd restart
every hour restart Apache

* 23-7 /. 1 * * * the restart /usr/local/etc/rc.d/lighttpd
23:00 between 7 am, every hour restart apache

0 4 *. 11 Mon-Wed /usr/local/etc/rc.d/lighttpd the restart
of each month 4 11:00 every Monday to Wednesday restart apache

0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
January 1st of 4:00 to restart apache

* / 30 * * * * / usr / sbin / ntpdate 210.72.145.44
every half hour about time synchronization

 

[Note] script should call timer in it plus: source / etc / profile (variable problem), plus if you do not perform alone could lead to the success of the statement by the timer, the timer execution was not successful.

 

 

Transfer from: http: //hi.baidu.com/faoduqsldrimrwe/item/a7c474d7bb8280cbcb0c393a qq-pf-to = pcqq.temporaryc2c?

Guess you like

Origin www.cnblogs.com/carsonwuu/p/11418641.html