意識の高いLISPマシン

藤原惟/すかいゆき(@sky_y)の技術用ブログ

crontab -eと/etc/crontabの違いについて

以前、crontabの設定でハマったので、メモしておきます。


結論から書くと、crontab -eで書くファイルと、システムcrontab(/etc/crontab)は書式が違います。
違いはユーザ名の有無です。
man 5 crontab より引用:

system crontab (/etc/crontab) uses the same format, except that the username for the command is specified
after the time and date fields and before the command. The fields may be separated by spaces or tabs.


実際の例で見てみましょう。

crontab -e の場合(ふつうのcrontabファイル)

ユーザ名がない。

# m h dom mon dow    command
17 *    * * *   cd / && run-parts --report /etc/cron.hourly
25 6    * * *   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

/etc/crontab の場合(システムcrontabファイル)

ユーザ名がある。

# m h dom mon dow user    command
42 6 * * *        root    run-parts --report /etc/cron.daily
47 6 * * 7        root    run-parts --report /etc/cron.weekly
52 6 1 * *        root    run-parts --report /etc/cron.monthly


なんかcronが実行されてないな、と思ったらチェックしてみてください。