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
-
Linux Now Runs Most Windows Games
The latest data shows that nearly 90 percent of Windows games can be played on Linux.
-
Fedora 43 Has Finally Landed
The Fedora Linux developers have announced their latest release, Fedora 43.
-
KDE Unleashes Plasma 6.5
The Plasma 6.5 desktop environment is now available with new features, improvements, and the usual bug fixes.
-
Xubuntu Site Possibly Hacked
It appears that the Xubuntu site was hacked and briefly served up a malicious ZIP file from its download page.
-
LMDE 7 Now Available
Linux Mint Debian Edition, version 7, has been officially released and is based on upstream Debian.
-
Linux Kernel 6.16 Reaches EOL
Linux kernel 6.16 has reached its end of life, which means you'll need to upgrade to the next stable release, Linux kernel 6.17.
-
Amazon Ditches Android for a Linux-Based OS
Amazon has migrated from Android to the Linux-based Vega OS for its Fire TV.
-
Cairo Dock 3.6 Now Available for More Compositors
If you're a fan of third-party desktop docks, then the latest release of Cairo Dock with Wayland support is for you.
-
System76 Unleashes Pop!_OS 24.04 Beta
System76's first beta of Pop!_OS 24.04 is an impressive feat.
-
Linux Kernel 6.17 is Available
Linus Torvalds has announced that the latest kernel has been released with plenty of core improvements and even more hardware support.

