Centos – Is it possible to have a cron job run more frequently than once every minute

centoscron

CentOS 6

I have a shell script that performs a task every minute. The task itself only takes a couple seconds to complete and ideally I'd like to have this shell script execute 2-3 times per minute. Is that possible to do with cron? Or is the fastest interval once every 60 seconds?

Best Answer

cron's manpage says that

cron(8) examines cron entries once every minute.

so its resolution is 60 seconds by design. You could have a cron job that calls the script more than once, but you'll have to be careful that the jobs don't start overlapping each other in case the script takes longer than expected.

If you really need (say) execution every 30 seconds, you'd be better off wrapping your script in a loop and daemonising it. You'll have to write your own error handling, as you won't be able to rely on cron emailing you errors any more.

Related Question