How to get a unix script to run every 15 seconds?

command, cron, sleep, unix

Solution

I would use cron to run a script every minute, and make that script run your script four times with a 15-second sleep between runs.

(That assumes your script is quick to run - you could adjust the sleep times if not.)

That way, you get all the benefits of `cron` as well as your 15 second run period.

Edit: See also @bmb's comment below.

Problem

I've seen a few solutions, including watch and simply running a looping (and sleeping) script in the background, but nothing has been ideal. I have a script that needs to run every 15 seconds, and since cron won't support seconds, I'm left to figuring out something else. What's the most robust and efficient way to run a script every 15 seconds on unix? The script needs to also run after a reboot.

Original source

Related problems