Running a cron job every 30 seconds

Standard cron cannot do it: the smallest unit is a minute. The usual workaround is a job that runs every minute and does its work twice, 30 seconds apart.

Next runs (your time zone)

    This tool runs in your browser. We never send what you type or paste to a server.

    The expression

    * * * * *  /path/to/command
    * * * * *  sleep 30; /path/to/command

    The expression has five fields, read left to right:

    FieldValueMeaning here
    Minute*every minute
    Hour*every hour
    Day of month*every day of the month
    Month*every month
    Day of week*every day of the week

    There is no sixth field for seconds in a crontab. * * * * * is the most frequent schedule cron has. The second line starts at the same moment as the first, waits 30 seconds and then runs the command, which gives a run at :00 and a run at :30 of every minute.

    When it runs

    Starting from Wed 2027-01-06 10:07 UTC, the next runs are:

    Wed 2027-01-06 10:08
    Wed 2027-01-06 10:09
    Wed 2027-01-06 10:10

    Each of those is a start of both crontab lines, so the command itself runs at :00 and :30 of each minute.

    Cron uses the time zone of the machine or service that runs it. The explainer at the top of this page shows the next runs in your own time zone.

    Better options than sleep

    The two-line trick is fine for something small. It has weak points: cron starts the minute a second or so late under load, nothing stops two runs overlapping, and a 10-second interval needs six lines. If the interval matters, use a tool built for it.

    A systemd timer has sub-minute intervals and never starts a run while the last one is active:

    # /etc/systemd/system/poll.timer
    [Timer]
    OnBootSec=30s
    OnUnitActiveSec=30s
    AccuracySec=1s
    
    [Install]
    WantedBy=timers.target

    It triggers poll.service, a unit of the same name. AccuracySec matters: the default is one minute, which lets systemd delay each run by up to that much.

    A loop in a long-running service is often simplest of all:

    while true; do /path/to/command; sleep 30; done

    Run it under systemd, supervisord or a container with a restart policy. Note that this waits 30 seconds after each run finishes, so the period is 30 seconds plus the run time.

    Ask whether polling is the right tool

    A job that must run every few seconds is usually waiting for something to happen. A queue, a file-system watch (inotifywait), a database notification or a webhook reacts at once and does no work in between. Cron is designed for jobs measured in minutes and hours.

    The same schedule in other schedulers

    SchedulerExpression
    Unix cron, crontab* * * * *
    Kubernetes CronJobschedule: "* * * * *"
    GitHub Actions- cron: '* * * * *'
    Quartz (Java, Spring)0/30 * * * * ?
    AWS EventBridgeNot possible in one expression

    Quartz has a seconds field, so 0/30 * * * * ? really is every 30 seconds. AWS EventBridge has no seconds: its shortest schedule is one minute, rate(1 minute). GitHub Actions will not go below 5 minutes, and a Kubernetes CronJob not below one.

    Questions

    Can cron run a job every 30 seconds?

    Not directly. Standard cron has no seconds field and its shortest interval is one minute. Use two entries, one of them starting with "sleep 30;", or a systemd timer.

    Does a six-field cron expression with seconds work in crontab?

    No. A crontab line has exactly five time fields followed by the command; a sixth value would be read as the start of the command. Six-field expressions belong to Quartz, Spring and some libraries such as node-cron.

    How do I run a cron job every 10 seconds?

    With cron you would need six lines sleeping 0, 10, 20, 30, 40 and 50 seconds. A systemd timer with OnUnitActiveSec=10s, or a loop inside a service, is cleaner.