Should I use cron.hourly or crontab?
crontab -e
is the traditional way to create a crontab. I find it to be awkward and old-fashioned, but people still use it.
/etc/cron.hourly
, including cron.daily
, cron.weekly
& /etc/cron.d
, etc. are provided by most Linux distros because they are convenient and work well with automation tools like package-managers and configuration management systems. It's very easy for a package manager to drop a file into /etc/cron.hourly/foo
compared to scripting an edit an existing crontab. Editing a file programmatically through a package manager might corrupt the file, add duplicate entries, delete the wrong line, screw up comments, etc. See Editfiles Considered Harmful for some discussion, as this problem has been around for a while.
Does running a crontab command create an entry in the specified cron folder?
No. /etc/cron.daily/foo
is created by the package manager, or created by hand. It is not created when you run the crontab command. crontab -e
will create the crontab under /var
, such as /var/spool/cron/root
.
I prefer /etc/cron.$period/foo
and /etc/cron.d
because that hierarchy is neat and organized, and it's easy to script for my Configuration Management system. /etc/crontab
is also available on Linux, but it's a bit monolithic and hard to edit programmatically. Systems like FreeBSD support /etc/crontab
and /etc/periodic
.