What is the difference when I put crontab entry in crontab -e (the default location is : /var/spool/cron/username ) and in /etc/crontab? I mean crond daemon will essentially execute both cron jobs. Then why there are two different ways to schedule cronjob ? Which one preferred over the other ?
Crontabs are the configuration files used by Cron to run services. Crontabs hold the configurations for which service to run and when it should run. Services are nothing more than an execution path to a script or application with possible additional commands. Cronjobs are the individual entries in that Crontab file.
Anacron. Anacron is a periodic command scheduler just like cron. The only difference is that it does not need your computer to be always running. You can schedule your task to run at any time.
weekly and /etc/cron. monthly on daily, hourly, weekly and monthly basis. Crontab is a utility that maintains crontab files for individual users. Crontab file is a simple text file having a list of commands that are executed at specific times.
In cron if a machine is not running on time of a scheduled job then it will skip it, but anacron is a bit different as it first checks for timestamp of the job then decides whether to run it or not and if its timestamp is >=n(n is defined number of days) then runs it after a specified time delay.
The difference is that the crontab
command is the interface provided by the system for users to manipulate their crontabs. The /etc/crontab
file is a special case file used to implement a system-wide crontab. /var/spool/cron/crontabs/$USER
(or whatever the path happens to be) is an implementation detail.
If you can schedule jobs using the crontab
command, you should do so.
Manually editing the contents of /etc/crontab
(a) requires root access, and (b) is more error-prone. You can mess up your system that way.
If the jobs are to be run under your own user account, there's no need to use root access.
Even if the jobs are to run as root
, it probably still makes more sense to use the crontab
command invoked from the root
account. (For one thing, it should detect syntax errors in the file.)
Personally, I don't use crontab -e
. Instead, I have a crontab file that I keep in a source control system, and I use the crontab filename
form of the command to install it. That way, if I mess something up, it's easy to revert to an earlier version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With