Linux – Should I use cron.hourly or crontab

awstatscronlinux

It seems that all the suggestions for using/scheduling awstats is via crontab, as such:
0 * * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=mysite -update >/dev/null (running awstats hourly).

However, if I check crontab -l, it says crontab is empty for my user.

However, when I check the /etc/cron.hourly, I've got an awstats file with the following:

#!/bin/bash
exec /usr/share/awstats/tools/awstats_updateall.pl now         -configdir="/etc/awstats"           -awstatsprog="/usr/share/awstats/wwwroot/cgi-bin/awstats.pl" >/dev/null
exit 0

Just to let you know, my awstats is updated fine, it creates its reports, and all is good.

Does running a crontab command create an entry in the specified cron folder? (ie cron.hourly or cron.daily, etc) ? Or are they unrelated? If they are related, why is my user without a crontab entry?

Best Answer

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.