Urgent.News

What's breaking now, across thousands of outlets.

Tech

What a Cron Expression Actually Means (With Examples)

Cron is the classic Unix job scheduler, and its schedule syntax has spread far beyond it: CI pipelines, cloud schedulers, and job queues all accept cron expressions. The syntax is compact, which makes it easy to get subtly wrong. Here is how to read and write it with confidence. The five fields A standard cron expression has five space-separated fields. Read left to right, they say when a job…

Cron is a well-known Unix job scheduler, and its schedule syntax has become widely used in various systems such as CI pipelines, cloud schedulers, and job queues. The syntax is succinct, but it can be easily misinterpreted. Here's how to read and write it with confidence.

A standard cron expression consists of five space-separated fields, read from left to right, specifying when a job should run: minute, hour, day of month, month, and day of week. Each field ranges from 0 to 59, 0 to 23, 1 to 31, 1 to 12, and 0 to 6, respectively (Sunday = 0).

For example, a job runs when the current time matches all five fields. The asterisk (*) signifies every possible value for that field. Commas (,) separate a list, such as 1,15 representing the 1st and 15th. Hyphens (-) define a range, like 1-5 denoting 1 through 5 (Monday to Friday in the day-of-week field). Forward slashes (/) signify a step, meaning */15 equals every 15 units, and 10-40/10 stands for 10, 20, 30, and 40.

Common schedules include:

- */5 * * * * for running every 5 minutes.

- 0 * * * * for running at the top of every hour.

- 0 9 * * 1-5 for running at 09:00 on weekdays.

- 30 2 * * 0 for running at 02:30 every Sunday.

- 0 0 1 * * for running at midnight on the first of every month.

- 0 0 1 1 * for executing once a year, at midnight on 1 January.

- 15 14 1 * * for running at 14:15 on the 1st of each month.

There are several pitfalls that could lead to missed jobs. Time zones are a common issue, as Cron runs in the time zone of the machine or service, which is often UTC. A job set to "9 AM" may fire at 9 AM UTC instead of in your local time. Cloud schedulers typically allow you to set a time zone explicitly, so it is essential to check before assuming.

In classic Vixie cron, if both the day-of-month and the day-of-week fields are restricted, the job runs when either one matches, not both. For instance, 0 0 13 * 5 fires on every 13th and on every Friday, not only on Friday the 13th.

Some systems, such as Quartz, Spring, and AWS EventBridge, add a seconds or year field, resulting in six or seven fields. Some dialects support names like MON or JAN and shortcuts like @daily or @hourly, while others do not. Daylight saving time can also cause issues in local time zones that observe it, as jobs scheduled during the skipped hour may not run, and those in the repeated hour may execute twice. Scheduling in UTC eliminates this problem.

Before deploying your cron expression, it's a good practice to paste it into a parser and read the plain-English translation. If it doesn't match your intended schedule, make the necessary adjustments before it inadvertently runs at the wrong time in production.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Why You Should Remove EXIF Data Before Sharing Photos

Every photo from a phone or camera carries a block of hidden information called EXIF (Exchangeable Image File Format) metadata.

  • Removing EXIF data before sharing photos prevents revealing personal information.
  • EXIF metadata includes device specifics, timestamps, and location data.
  • Use browser-based tools to strip metadata without uploading photos.

JSON vs YAML: When to Use Which

JSON and YAML can describe the same data, so the choice comes down to who (or what) reads and writes the file. JSON is strict, small, and easy for software to parse.

  • JSON is strict and compact, ideal for software parsing
  • YAML is forgiving and user-friendly for humans
  • Use JSON for software-to-software data exchange

How to Decode a JWT Safely (Without Sending It to a Server)

A JSON Web Token (JWT) looks like an opaque blob, but it is just three Base64URL-encoded pieces joined by dots. Anyone who holds the token can read what's inside; no secret key is needed.

  • A JWT consists of three encoded sections linked by dots
  • Header and payload can be decoded into JSON to reveal metadata and claims
  • Signature remains untouched as binary data, do not decode it

Apple Pay Token Decryption vs Google Pay ECv2

Apple's own reference page for decrypting an Apple Pay token currently gets the key derivation wrong. The KDF table lists the hash function where the shared secret should be, and it has dropped the…

More from Saturday 26 September →