Long story short: I accidentally deleted the default content that the 64-bit Ubuntu 20.04 installer had put inside of /etc/crontab
during Ubuntu's installation on my computer, so now I'm trying to find out if it's possible to obtain an exact copy of such file from either the interior of the Ubuntu ISO installation file (e.g. a "local repository" such as ubuntu-20.04-amd64.iso
) or from a remote repository (e.g. hosted at ubuntu.com or something) so I can put this default crontab
file back in /etc
.
I mounted the Ubuntu 20.04 ISO and ran sudo ls -lR | grep -i crontab
inside of it, but no crontab
file was found, thus I imagine that it may be compressed inside one of the files inside of such ISO file, or maybe a system crontab is available for download somewhere at the ubuntu.com network or Launchpad's PPA: I just don't know.
Short story long:
While using pipelining with |
, in order to append the 1-line output of a command to /etc/crontab
, I accidentally typed:
| sudo tee /etc/crontab
...instead of:
| sudo tee -a /etc/crontab
...and therefore ended up replacing the entire content of /etc/crontab
with just 1 line, instead of adding such 1 line to the end of such file. Despair!
To my luck, though, this was the first time that I was attempting to modify such file, therefore its content was the default one created by Ubuntu during its installation. But what content is it?
I decided to run info crontab
and found what seems to be the same default content of /etc/crontab
(but I'm not really sure):
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Example of job definition:
#.-------------<-------- minute (0 - 59)
#| .------------<------- hour (0 - 23)
#| | .-----------<------ day of month (1 - 31)
#| | | .----------<----- month (1 - 12) OR jan,feb,mar,apr ...
#| | | | .---------<---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
#| | | | | .-------<--- user
#| | | | | | .--<-- command
#| | | | | | |
#v v v v v v v
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 )
I then decided to save the above code in a brand-new /etc/crontab
file with owner:group = root:root (sudo chown root:root /etc/crontab
) and then restore its permissions with sudo chmod 755 /etc/crontab
. After I did this, I also created a backup copy of it with sudo cp /etc/crontab /etc/crontab.bak
and also created a skeleton (i.e. template) of it with sudo cp /etc/crontab /etc/skel/crontab
...
...but I can't help but wonder if the code above is indeed the exact same one that the Ubuntu 20.04 installer had created inside of /etc/crontab
during Ubuntu's installation, nor do I know how to obtain an exact copy of such original/default file (if any is available somewhere).
/etc/crontab
created by Ubuntu does indeed have the same content of the example code shown byinfo crontab
. I wonder, though, if this file is available somewhere for copy/download, or if this info crontab workaround is the only way. – Yuri Sucupira Dec 14 '20 at 10:26/etc/cron.hourly|daily|weekly|monthly
directory instead of modifying/etc/crontab
. It's definitely safer. – Yuri Sucupira Dec 14 '20 at 10:41