Ubuntu – What’s the difference between /etc/cron.hourly and crontab -e

bashcronscripts

What's the difference between creating a script in

/etc/cron.hourly/myScript

Or adding the script in crontab -e with:

# m h  dom mon dow   command
0 * * * * myScript

When I run crontab -l or sudo crontab -l I don't see the scripts created in /etc/cron.*

Is there any advantage of using one or the other?

Best Answer

User crontab files (the kind produced by non-root crontab -e) are stored in /var/spool/cron/crontabs/<user>. root cron jobs are run through /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly, and controlled via /etc/crontab. The comments at the top of /etc/crontab say:

# /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.