Linux provides three different job schedulers i.e. Cron, Anacron and Systemd-Timer. What are the benefits of Cron/Anacron vs. Systemd-Timer?
Asked
Active
Viewed 2,807 times
1 Answers
10
In favor of Cron
- A simple one line entry /etc/crontab and your job is set to run
In favor of systemd
- Consistent run time environment with the same environment variable set. This solves a common problem with Cron jobs: They run fine in one environment and not via cron because different PATH or other values in the environment.
- Better logging!
systemdcaptures STDOUT and STDERR of your job and stores it in the systemd journal. - Better job status. You can use
systemctl status your-serviceto check the status of what you ran. Outside of combing logs, cron offers no structured way to query the service status. - Better timer status. Use
systemctl list-timersto get a summary of enabled timers and see when they last ran and when they will next run.
In summary
Systemd timers have some overhead to learn and setup, but provide a number of benefits. There some packages like systemd-cron and systemd-cron-next that allow you to have cron entries converted to systemd-timers, to try to provide a best-of-both-worlds solution
Mark Stosberg
- 3,447