How to run cron jobs every 5, 10, or 30 seconds?

Better Stack Team
Updated on May 4, 2022

By default, cron checks crontabs for cronjobs every minute. If you want to run a job every n seconds you need to use a simple workaround.

Specify multiple jobs with offsets

The easiest way to run a job every n seconds is to run a job every minute and, and sleep in a loop in n second intervals.

Every 5 seconds

/script.sh:
i=0

while [ $i -lt 12 ]; do # 12 five-second intervals in 1 minute
  command/to/run & #run your command
  sleep 5
  i=$(( i + 1 ))
done
Copied!
/etc/crontab:
* * * * * script.sh
Copied!

Every 10 seconds

/script.sh:
i=0

while [ $i -lt 6 ]; do # 6 ten-second intervals in 1 minute
  command/to/run & #run your command
  sleep 10
  i=$(( i + 1 ))
done
Copied!
/etc/crontab:
* * * * * script.sh
Copied!

Every 15 seconds

/script.sh:
i=0

while [ $i -lt 4 ]; do # 4 ten-second intervals in 1 minute
  command/to/run & #run your command
  sleep 15
  i=$(( i + 1 ))
done
Copied!
/etc/crontab:
* * * * * script.sh
Copied!

Every 30 seconds

/script.sh:
i=0

while [ $i -lt 2 ]; do # 2 ten-second intervals in 1 minute
  command/to/run & #run your command
  sleep 30
  i=$(( i + 1 ))
done
Copied!
/etc/crontab:
* * * * * script.sh
Copied!

Every 30 seconds (different way)

/etc/crontab:
* * * * * script.sh
* * * * * sleep 30 ; script.sh
Copied!
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack