Crontab Every 30 Seconds (Workaround)

Cron's minimum resolution is 1 minute, but you can achieve sub-minute scheduling using a sleep workaround. Learn how to run a job every 30 seconds.

Special Strings* * * * * /cmd; sleep 30 && /cmd

Detailed Explanation

Running a Job Every 30 Seconds with Cron

Standard cron has a minimum resolution of one minute — you cannot schedule a job more frequently than * * * * * (every minute). However, a common workaround uses the sleep command to achieve sub-minute intervals.

The Workaround

* * * * * /path/to/script.sh
* * * * * sleep 30 && /path/to/script.sh

This creates two crontab entries:

  1. The first runs the script at the top of every minute (:00)
  2. The second waits 30 seconds and then runs the script (:30)

Together, they execute the script every 30 seconds.

How It Works

At each minute tick, cron fires both entries simultaneously. The first entry runs the script immediately. The second entry executes sleep 30 (which blocks for 30 seconds), then runs the script. The net effect is execution at :00 and :30 of every minute.

Limitations

  • Process overhead: Each cron invocation spawns a new shell process
  • No overlap protection: If the script takes more than 30 seconds, runs will overlap
  • Scaling: For intervals like every 10 or 15 seconds, you need more entries:
* * * * * /cmd
* * * * * sleep 15 && /cmd
* * * * * sleep 30 && /cmd
* * * * * sleep 45 && /cmd

Better Alternatives

For sub-minute scheduling in production, consider:

  • systemd timers with OnUnitActiveSec=30s
  • A loop-based daemon with sleep intervals
  • Message queues for event-driven processing
  • Watch/polling tools like inotifywait

Use Case

Sub-minute scheduling is sometimes needed for near-real-time data processing, health check endpoints with strict SLA requirements, stock ticker updates, chat bot polling, or development/testing scenarios where you need rapid feedback loops.

Try It — Crontab Cheat Sheet

Open full tool