centos in crontab (timer) Detailed usage

About crontab :

  crontab command in common in Unix and Unix operating system, an instruction set 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. The word comes from the Greek chronos (χρ? Νο?), The intent is the time.
  Typically, the instructions are stored crontab daemon activated, crond often run in the background every minute to check for scheduled jobs need to be performed. Such work is generally known as cron jobs.

 

Installation crontab:

[root@CentOS ~]# yum install vixie-cron
[root@CentOS ~]# yum 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.

cron is a linux built-in services, but it does not auto-up, you can start with the following methods to close this service:

/ sbin / Service crond Start # Start Service
/ sbin / Service crond STOP # shut down service / sbin / Service crond restart # restart the service / sbin / Service crond reload # reload the configuration

 

View crontab service status:

service crond status

 

Crontab manually start the service:

service crond start

 

Other commands:

Copy the code
# See if crontab service is set to boot, execute the command:
 ntsysv

# Join at startup: --level 35 chkconfig crond ON # list the crontab file crontab - L # edit the crontab file crontab - E # delete crontab file crontab $ - r # recover lost crontab file # assume that you have a backup in his $ HOME directory , you can copy it to / var / spool / cron / < username>, where <username> is the user name # or use the following command where, <filename> is the file name crontab your copy in $ HOME directory <filename>
Copy the code

 

Log file: / var / log / cron *  

 

supplement:

1, crontab related commands

Function: Set the timer.

Syntax: crontab [-u <user name>] [Profile] or crontab [-u <user name>] [- elr]

Supplement: cron is a permanent service, which provides a timer feature that allows users to execute commands or preset program at a particular time. As long as a user can edit the timer configuration file, you can use the timer function.

Configuration file format: Minute Hour Day Month dayOfWeek the Command

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

 

2, crontab configuration file format

  The basic format:
  * * * * * the Command
  when the sun and the moon weeks divided command

  Column 1 represents minute 1 to 59 with * or * / 1 expressed per minute
  of the second column shows the hours 1 to 23 (0 represents 0:00)
  the third column indicates 1 to 31
  fourth column represents the month 1 to 12
  of 5 identification numbers 0 to 6 weeks (0 Sunday)
  command to run the first 6

 

Some examples of crontab file:

# Nightly 21:30 restart apache
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
# Month 1, 10, 22 May 4:45 restart apache
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
# Saturday, Sunday 1:10 to restart apache
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
# 18 every day: 00-23: every 30 minutes between 00 to restart apache
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
# Every Saturday in 11: 00 pm restart apache
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
# Between 23:00 to 7 am, every hour restart apache
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
# Every hour restart apache
* */1 * * * /usr/local/etc/rc.d/lighttpd restart
# Monthly number 4 and 11:00 from Monday to Wednesday to restart apache
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
# 1 January of 4:00 to restart apache
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
# Every half hour about time synchronization
*/30 * * * * /usr/sbin/ntpdate 210.72.145.44

 

3. Other task scheduling

cron default configuration of scheduled tasks, namely: hourly, daily, weekly, mouthly, the default configuration file is / etc / anacrontab

The script needs to be executed into the appropriate directory can, directory 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 .centos in crontab -e Detailed usage. Http://hi.baidu.com/ldbf/blog/item/b4dc9e02f23dcb124bfb51b8.html

  [3] Bird Brother Linux private kitchens. Routine Task Scheduler (crontab). Http://linux.vbird.org/linux_basic/0430cron.php

  [4] Comparative several implementations DELL-Richard Li.Linux the cron scheduling. Http://zh.community.dell.com/techcenter/f/21/t/1185.aspx

Reproduced in: https: //www.cnblogs.com/zhangchenliang/p/4191194.html

Guess you like

Origin blog.csdn.net/weixin_34221112/article/details/93495490