cron デーモンは、スケジュールされたシステム ジョブを実行するように構成できます。システム ジョブの場合、コマンドを実行する権限を持つユーザーも指定する必要があります。時間定義 (最初の 5 つのフィールド) とコマンド (7 番目のフィールドになる) の間にユーザー名を入力します。
システム ジョブは、/etc/crontab ファイルまたは /etc/cron.d/ ディレクトリ内のファイルで定義します。 CentOS/RHEL システムのデフォルトの crontab は次のとおりです。
# 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注意 注:/etc/crontab に行を追加することはできますが、デフォルトの行は削除しないでください。
上記の /etc/crontab ファイルで定義されたジョブは、指定された間隔で次のディレクトリに含まれるスクリプトを実行します:
ディレクトリ | 間隔 |
---|---|
/etc/cron.hourly | /etc/cron.hourly 1 時間ごとに実行されるジョブ。 |
/etc/cron.daily | 日常的に実行されるジョブ |
/etc/cron.weekly | 毎週実行されるジョブ |
/etc/cron.monthly | 毎月実行されるジョブ |
# 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