NadirTools

Non-Standard Cron Implementations: Unix, AWS, and systemd

2 min read

Compare scheduling variations across classic Unix, AWS EventBridge, and systemd timers.

Linux Vixie Cron vs. Modern Schedulers

Standard Unix (Vixie) cron uses 5 fields. However, as cloud computing evolved, scheduling requirements became more precise, leading to non-standard implementations with 6 or 7 fields.

AWS CloudWatch / EventBridge

AWS cron syntax uses 6 fields: `cron(Minutes Hours Day-of-month Month Day-of-week Year)`. Notably, AWS requires that you cannot specify `*` in both the Day-of-month and Day-of-week fields simultaneously. One must be replaced with a question mark `?` to indicate 'no specific value'.

Quartz Scheduler (Java / Spring)

The Quartz scheduler uses 7 fields, adding a seconds field at the very beginning and an optional year field at the end. This allows for sub-minute precision, which standard cron cannot achieve.

systemd Timers: The Modern Linux Alternative

On modern Linux systems, systemd timers (`.timer` units coupled with `.service` units) are rapidly replacing standard cron jobs. They offer massive advantages for sysadmins:

1. **Monotonic Timers**: Timers can run tasks relative to boot time (`OnBootSec=`) or service activation, rather than relying on strict calendar time (`OnCalendar=`).

2. **Detailed Logging**: Console output from triggered services is captured automatically in `journald`, eliminating the need to pipe output to `/var/log/syslog` manually.

3. **Resource Control**: Jobs triggered by systemd can be heavily throttled using cgroups to prevent background tasks from starving the CPU of foreground applications.

Frequently Asked Questions

Q: Why does AWS cron use a question mark (?)

AWS uses 6 fields and requires the question mark to resolve conflicts between the Day-of-month and Day-of-week fields. If you specify a day of the month, you must use ? for the day of the week, and vice versa.

Q: Can standard cron run jobs every second?

No. Standard Unix cron has a maximum resolution of one minute. To run jobs by the second, you must use systemd timers, the Quartz scheduler, or write a loop script with a sleep command.

Q: Why are systemd timers better than cron?

Systemd timers integrate directly into journalctl for logging, can trigger based on system events rather than just clocks, and can restrict CPU and RAM usage via cgroups.