This question already has an answer here:

In my attempt to make a new crontab file work on 16.04, I made the following mistake as root:

sudo su root
crontab /etc/cron.d/myjob

I realized too late that I must've changed some default crontab behaviour, ie regarding crontab -e. I tried to roll back like this:

# still as root:
crontab /etc/crontab

Is that the correct default setting? If not, then what is?

PS: The related issue does not answer my question. The answer there only states how to remove a crontab, not how to re-generate the default Ubuntu installation settings which is what I need to know.

marked as duplicate by karel, Fabby, Eric Carvalho, MadMike, vidarlo May 5 '18 at 21:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Thanks. Your linked issue indicates that the original root crontab was empty. Mine wasn't. I didn't add anything to it myself; I don't know what was in there; I just caught a glimpse of it with crontab -e before I messed up. It was a 3 weeks old 16.04 Unity installation. It must've been the one that ships with the installation; is that /etc/crontab? – Jonas Ellehauge May 4 '18 at 6:29
  • Here is the contents of /etc/crontab: gist.github.com/ellvtr/c9f804e277d8bd3683766115c68a7877 – Jonas Ellehauge May 4 '18 at 6:47

Cron utilizes two, quite independent sets of crontab files.

  1. One of them is public (system-wide), located in /etc. It includes /etc/crontab and the files in /etc/cron.d.
    The file you linked looks much like the default /etc/crontab. If you have got this contents in your /etc/crontab file, keep it.

  2. The other includes a private file for each user. Their actual location is /var/spool/cron/crontabs but this folder is not accessible by normal means. These crontab files shall be accessed and modified using the crontab command.
    A user’s crontab (including root, accessed using sudo crontab <option>) does not exist by default. When you issue crontab -e and have no crontab file for given user, the command brings a template with no scheduled commands, just descriptive comments. The file is saved only if you modify the template.
    To reset this one to the default state (i.e. remove it), use the command:

    crontab -r
  • 1
    The user crontab is functionally empty but contains informative comments at the start, iirc. – muru May 4 '18 at 7:28
  • @muru You are almost right. If you open the empty crontab using crontab command, you get some placeholder comments. However, they aren’t stored in the /var/spool/cron/crontabs until you save your own crontab. – Melebius May 4 '18 at 7:29
  • sudo contab -e was not empty before I messed it up. It had actual jobs in there, not just the standard comments. If it was empty by the Ubuntu installation - I only got a short glimpse of it. I assume some applications have added root cronjobs after the installation then. – Jonas Ellehauge May 16 '18 at 6:03
  • 1
    @JonasEllehauge the root user's crontab is empty by default. Any packages that need to run cronjobs use the /etc/cron.* directories. No package edits the root user's crontab. – muru May 16 '18 at 6:15
  • Thanks, good to know. There were some entries in mine and I didn't add them manually. Here's what's in there now 17 * * * * root cd / && run-parts --report /etc/cron.hourly /n 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) [+more anacron entries]. Looks like anaconda added some. The first one looks like a system entry to me. – Jonas Ellehauge May 17 '18 at 6:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.