首页 > 技术文章 > cron on Centos

anor 2017-10-19 11:47 原文

1. crond.service

2. configuration

2.0 format


# Example of job definition: 
# .---------------- minute (0 - 59) 
# | .------------- hour (0 - 23) 
# | | .---------- day of month (1 - 31) 
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 
# | | | | | 
# * * * * * user-name command to be executed

2.1 per-user

/var/spool/cron/<user_name>

2.2 system-level

/etc/crontab
/etc/cron.d/

2.3 configure to run all script in a folder

First, create a folder and put all script into it

And then, use "run-parts", 
to create a configure item in one of cron configuraiton files, like this:

01 * * * * root run-parts /etc/cron.hourly

3. How to configure a cron job

3.1 directly add conf item into


/var/spool/cron/<user_name>
/etc/crontab

3.2 create a cron conf file and put it into

/etc/cron.d/

3.3 use crontab

crontab: invalid option -- 'h' 
crontab: usage error: unrecognized option 
Usage: 
crontab [options] file 
crontab [options] 
crontab -n [hostname] 

Options: 
-u <user> define user 
-e edit user's crontab 
-l list user's crontab 
-r delete user's crontab 
-i prompt before deleting 
-n <host> set host in cluster to run users' crontabs 
-c get host in cluster to run users' crontabs 
-s selinux context 
-x <mask> enable debugging 

4. cron log

/var/log/cron

5. anacron

asynchrous cron

5.1 cron trigger anacron:

/etc/cron.hourly/0anacron

5.2 anacron configuraiton

/etc/anacrontab


1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly


/etc/cron.d/0hourly ==> anacron ==> /etc/anacrontab/ ==> cron ==> /etc/cron.daily/cron.weekly/cron.monthly

推荐阅读