Cron every 30 seconds: */30 * * * * * and the two line trick
With a seconds field, */30 * * * * * fires at second 0 and second 30 of every minute, 2,880 times a day. Without one, two crontab lines and a sleep achieve the same cadence.
At a glance
- Expression
- */30 * * * * *
- Fires
- 2,880 times a day, 120 times an hour, twice a minute.
- Restricted fields
- Seconds only. Everything from the minute field onwards is open.
- Equivalent macro
- None.
- Seconds matched
- 0 and 30.
- Five field workaround
- Two lines: one plain, one prefixed with sleep 30.
In detail
Half a minute is the shortest interval most people actually need, and it is the one the sleep trick handles cleanly. In a six field scheduler you write */30 in the leading seconds field and get second 0 and second 30. In a system crontab you write the same job twice, once as it is and once behind a sleep 30, and the two lines interleave to give the same two runs a minute.
The interleaving is only as good as the runtime of the job. If the first copy takes longer than thirty seconds, the sleeping copy starts while it is still going, and the two are now overlapping rather than alternating. A lock does not help here, because skipping the second run turns a thirty second cadence into a sixty second one without saying so.
Both forms share a subtler issue: the second run of each minute belongs to the same cron tick as the first. If the daemon is stopped between them, you lose the second run and not the first, so a restart during that window produces one missing sample rather than a clean gap. Anything comparing consecutive samples should read timestamps rather than assume spacing.
As with any sub minute schedule, check whether the thing being polled supports being asked less often. Thirty second polling of an endpoint that only updates every five minutes is 2,880 requests a day to learn something 288 requests would have told you.
Examples
*/30 * * * * ** * * * * /opt/app/bin/probe.sh >> /var/log/probe.log 2>&1
* * * * * sleep 30; /opt/app/bin/probe.sh >> /var/log/probe.log 2>&1*/30 * 2-4 * * *Six fields: seconds 0 and 30, any minute, hours 2, 3 and 4. 360 runs a night.
Things that catch people out
- sleep 30 inside a crontab line needs the whole command to be shell safe. Write it as a single command list, and quote anything containing a space.
- If the job writes a file named after the current minute, both runs of the minute write the same name and one result is lost.
- A six field expression pasted into a five field scheduler is rejected on field count, which usually reads as a confusing error about the day of week field.
Try it: Cron Expression Parser
Paste any five or six field expression to get a plain English description, a per field breakdown and the next run times in your local time.
Cron Expression Parser
LOCAL · Browser-OnlyParse cron expressions and see the next scheduled run times
Supports 5-field (minute hour day month weekday), 6-field (with seconds), named values (JAN, MON), and @macros (@daily, @hourly, ...)
Use the dropdowns below to build your cron expression visually, or type a custom value in each field.
Human-Readable Description
Every 5 minutes
Field Breakdown
| Field | Allowed | Value | Meaning |
|---|---|---|---|
| Minute | 0-59 | */5 | every 5 minute(s) |
| Hour | 0-23 | * | every hour |
| Day of Month | 1-31 | * | every day of month |
| Month | 1-12 | * | every month |
| Day of Week | 0-7 | * | every day of week |
Related cron expressions
All cron expressions →Cron every 10 seconds: */10 * * * * * and the alternative
*/10 * * * * * fires 8,640 times a day at seconds 0, 10, 20, 30, 40 and 50. What to do when the scheduler only accepts five fields.
Cron every second: * * * * * * with a seconds field
Six asterisks means every second, 86,400 times a day. Standard crontab has no seconds field, so this form only works in schedulers that accept six.
Cron every minute: * * * * *
* * * * * fires 1,440 times a day, once at the top of every minute. Why it is the fastest a five field crontab goes, and how to stop runs stacking.
The cron seconds field: the optional sixth position
A six field expression puts seconds first and shifts everything right. The system crontab has no seconds field, so six fields there means a broken job.
Cron every hour: 0 * * * *
0 * * * * fires 24 times a day at the top of every hour and is what @hourly expands to. Why * */1 * * * is the mistake people make instead.
Cron every hour at 30 minutes past: 30 * * * *
30 * * * * runs 24 times a day at half past every hour. How to pick an offset minute deliberately and why the top of the hour is worth avoiding.
Tools for this
- Cron Expression Parser Free online cron expression parser - parse cron expressions and see the next scheduled run times
- Crontab Generator Free online crontab generator - build cron expressions visually with an intuitive interface