The cron daemon can be configured to run scheduled system jobs. For system jobs, the user with whose permissions the command is run must also be specified. Enter the username between the time definition (the first five fields) and the command (which now becomes the seventh field).
You define system jobs in the /etc/crontab file or in files in the /etc/cron.d/ directory. A default crontab in CentOS/RHEL system is as shown below.
# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # 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
NOTE: While you can add additional lines to /etc/crontab, you should not delete the default lines.
The job defined in the above /etc/crontab file runs the scripts contained in the following directories at the intervals indicated:
Directory | Interval |
---|---|
/etc/cron.hourly | /etc/cron.hourly Jobs that run on an hourly basis. |
/etc/cron.daily | Jobs that run on a daily basis. |
/etc/cron.weekly | Jobs that run on a weekly basis. |
/etc/cron.monthly | Jobs that run on a monthly basis. |
# ls -lrt /etc/cron.hourly/ total 4 -rwxr-xr-x. 1 root root 392 Mar 29 2017 0anacron [root@jamiericho4 ~]# ls -l /etc/cron* -rw-------. 1 root root 0 Mar 29 2017 /etc/cron.deny -rw-r--r--. 1 root root 451 Dec 27 2013 /etc/crontab /etc/cron.d: total 16 -rw-r--r--. 1 root root 128 Mar 29 2017 0hourly -rw-r--r--. 1 root root 173 Sep 23 2016 awslogs -rw-r--r--. 1 root root 179 Sep 23 2016 awslogs_log_rotate -rw-r--r--. 1 root root 108 Jun 13 2017 raid-check /etc/cron.daily: total 16 -rwx------. 1 root root 219 Jan 24 2017 logrotate -rwxr-xr-x. 1 root root 618 Mar 17 2014 man-db.cron -rwx------. 1 root root 208 Feb 4 2016 mlocate -rwx------. 1 root root 256 Sep 1 10:34 rhsmd /etc/cron.hourly: total 4 -rwxr-xr-x. 1 root root 392 Mar 29 2017 0anacron /etc/cron.monthly: total 0 /etc/cron.weekly: total 0