Running a Job Every 30 Seconds
Standard cron resolution is one minute, so there is no direct "every 30 seconds". The common trick is two lines per minute: one runs now, one runs after sleep 30.
The two-line trick
* * * * * /path/job.sh* * * * * sleep 30; /path/job.sh
The first line fires at the top of each minute; the second waits 30 seconds, giving a 30-second cadence.
Cleaner: systemd timer
For true sub-minute scheduling use a systemd timer with OnUnitActiveSec=30s. It survives reboots and logs to the journal.
Watch for overlap
If the job can take longer than 30s, guard it with flock so two copies never run at once: flock -n /tmp/job.lock /path/job.sh.
FAQ
Can cron run every 30 seconds?
Not directly — cron resolution is one minute. Use two lines (one with sleep 30) or a systemd timer with OnUnitActiveSec=30s.
How does the sleep 30 trick work?
One crontab line runs at the start of the minute; a second line runs sleep 30 then the job, so it executes at the 30-second mark.
Is a systemd timer better than the sleep trick?
Yes for reliability — it handles overlap, reboots and logging cleanly, which the sleep trick does not.