WRONG FILE OWNER (/etc/crontab)

This is in my syslog. Is it there because I made my self the owner of crontab?

Aug 9 08:39:01 7 cron[917]: (*system*) WRONG FILE OWNER (/etc/crontab)

Thanks.

Yes indeed, that is exactly the case.
It might be a good idea to do:

sudo chown root:root /etc/crontab

I made myself the owner to make it easier to edit crontab.

Well .... You actually are giving up security for convenience then.
Good that your system is watching over you :wink:

if sudo pluma /etc/crontab is too much work, you are probably editing it multiple times a day. You might want to change that habit:
/etc/crontab is not for user purposes but for system purposes.

If you, as a user, needs a cronjob; use the command crontab
man crontab
Every user can have its own crontab and it is independent from the system crontab.

An alternative is the at command which is specially geared towards one-off actions.

Ask yourself if you actually need to edit /etc/crontab.
Let's for example look at my usecase:

For the sake of the argument, let's say:

  1. I have a custom made program that generates logs
  2. I want those logs cleaned up after several days
  3. I make a cleanup program to delete logs older than that few days
  4. I want that cleanup program to run every day.

I could edit /etc/crontab, but this would be the wrong way to go.
It is better and much more convenient to dump my cleanup program (or a link to it) in /etc/cron.daily

These crondirectories are on the system:
/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly
/etc/cron.monthly

The contents of these directories are executed by /etc/crontab this way:

17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

the command run-parts runs all the executable files in the given directory in numerical/alphabetical order.
Here you can see that they all, except cron.hourly, start between 6 and 7 am.

Although I do several timed background jobs on some servers as well as my computers at home, I haven't touched /etc/crontab for many years. I mean, they are still the default that comes with the install.
I exclusively use /etc/cron.daily and its weekly and monthly siblings.

p.s. You might have discovered that I lied a little bit about cron running run-parts because I didn't want the implementation details muddeling the explanation.

If you want the straight facts, here they are:

if anacron is installed in the system (which it is by default on ubuntu), it is actually anacron which is triggered by systemd (anacron.timer) every hour.
cron won't do the hourly, daily, weekly or monthly if anacron is available.

The actual daily and weekly triggers are set in
/etc/anacrontab
the timeperiod in that the hourly triggers are done are written in
/etc/systemd/system/timers.target.wants/anacron.timer
which is by default set to be enabled from 7:30 to 23:30 but this can be changed according to your needs

2 Likes