10

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?

Stefan Lasiewski
  • 22,949
  • 38
  • 129
  • 184
fizzy drink
  • 375
  • 4
  • 8
  • 22

1 Answers1

14

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.

Stefan Lasiewski
  • 22,949
  • 38
  • 129
  • 184
  • 1
    Thanks for your answer, I prefer it as well, as I'm used to dropping config files in .d folders (ie conf.d, etc)! – fizzy drink Sep 21 '14 at 16:19
  • I can only agree on this. I also prefer to use the system's `/etc/crontab` when it's about running system taks instead of using root's crontab. This way, one can easily know what the system is up to without digging in each user's crontab. – Spack Sep 22 '14 at 19:06
  • 1
    I agree with this answer. Maybe mention some other differences: /etc/cron.$period/ contain self-sufficient scripts that are run by user root. OTOH /etc/cron.d/ contains include files in `crontab -e` format. Finally, /etc/cron* is intended to root-run scripts, while `crontab -e` is available to all users. – Nils Toedtmann Sep 22 '14 at 22:17
  • The `crontab -e` command is awkward by default. So I created a script called `cte` which does two commands: `export EDITOR=gedit` and then `crontab -e` so the editor is easier to work with. – SDsolar May 03 '18 at 17:28