Comparing cron and systemd for task automation
Timer Time
Cron and systemd are two options for automating tasks in Linux. Which is best? That all depends…
Automation is a cornerstone of modern Linux system administration, bringing efficiency in executing repetitive tasks. In the past, the venerable and reliable cron utility was the go-to tool for automating recurring tasks. In recent years, however, a more modern alternative has emerged as a competitor to the classic cron: systemd timers. Although the systemd init system [1] has been around since 2010, setting timers through systemd still seems exotic and new to many Linux users. A large contingent of the Linux crowd never really had a problem with cron and has never seen any reason to switch. Still, systemd offers advanced features that aren't available with cron, and once you get past the learning curve, systemd timers aren't as complicated as they look. We decided it was time to compare these two powerful automation techniques side by side. We'll start with brief descriptions, then compare some of the pertinent features, and we'll end with a look at a few practical examples. If you're in need of some additional background, see the cron tutorial later in this issue.
Cron for Task Automation
Cron, derived from the Greek word "chronos" meaning time, is a time-based job scheduler in Unix-like operating systems [2]. Cron allows users to schedule commands or scripts, known as cron jobs, to run periodically at fixed times, dates, or intervals. The behavior of cron is governed by crontab (cron table) files. A crontab file is a configuration file specifying the schedule and the command you wish to execute [3]. Users can create their own crontab files, and there is typically a system-wide crontab file for administrative tasks.
The fundamental unit of cron is the cron job, which is defined by a specific syntax within the crontab file. Each line in a crontab represents a job and consists of a cron expression followed by the command to execute. The standard cron expression comprises five fields representing the minute (0-59), hour (0-23), day of the month (1-31), month (1-12 or JAN-DEC), and day of the week (0-6 or SUN-SAT). These fields are separated by spaces, and each can contain specific values, ranges, lists, or the asterisk (*) to denote all possible values within that field. For instance, * * * * /path/to/command would execute the specified command every minute.
[...]
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Gnome 50 Smooths Out NVIDIA GPU Issues
Gamers rejoice, your favorite pastime just got better with Gnome 50 and NVIDIA GPUs.
-
System76 Retools Thelio Desktop
The new Thelio Mira has landed with improved performance, repairability, and front-facing ports alongside a high-quality tempered glass facade.
-
Some Linux Distros Skirt Age Verification Laws
After California introduced an age verification law recently, open source operating system developers have had to get creative with how they deal with it.
-
UN Creates Open Source Portal
In a quest to strengthen open source collaboration, the United Nations Office of Information and Communications Technology has created a new portal.
-
Latest Linux Kernel RC Contains Changes Galore
Linux kernel 7.0-rc3 includes more changes than have been made in a single release in recent history.
-
Nitrux 6.0 Now Ready to Rock Your World
The latest iteration of the Debian-based distribution includes all kinds of newness.
-
Linux Foundation Reports that Open Source Delivers Better ROI
In a report that may surprise no one in the Linux community, the Linux Foundation found that businesses are finding a 5X return on investment with open source software.
-
Keep Android Open
Google has announced that, soon, anyone looking to develop Android apps will have to first register centrally with Google.
-
Kernel 7.0 Now in Testing
Linus Torvalds has announced the first Release Candidate (RC) for the 7.x kernel is available for those who want to test it.
-
Introducing matrixOS, an Immutable Gentoo-Based Linux Distro
It was only a matter of time before a developer decided one of the most challenging Linux distributions needed to be immutable.
