I have a crontab with different time to execute some task, for example every minute, every 10 min, 1 hour, daily... And i have a question, when some of this cron coincide in the same time for example, when 10 minutes execute, also execute 1 min cron and this cron execute in parallel... but I want to execute in sequence, for example all jobs in 1 minute, and the all jobs in 10 min... how can I do this??


With cron itself, I don't think you really can. I would probably script my way out of that: make a single script executed from cron every minute, and then run the tasks with separate intervals from that script. Something like this:

Crontab entry:

* * * * * /path/to/main_script.sh

And main_script.sh:

mins=$[ $(date +%s) / 60 ]           # current time, rounded to minutes
if [ $[ $mins % 10 ] -eq 0 ] ; then  # mins divisible by 10 ?
    run_10min_task.sh                # run the every 10 min task
if [ $[ $mins % 60 ] -eq 0 ] ; then  # same for 1 hour
if [ $[ $mins % 1440 ] -eq 0 ] ; then # 1440 = 24*60

You need to take into account the time zone if you care what hour the once-a-day task runs, the above should run it at 00:00 UTC. Compare to some other value than zero to change it.

Also, note that if your tasks can take more than 1 minute, you need to make sure they can cope with running simultaneously, or prevent them from doing that.

  • It's same works fine, thx – sdelcueto Oct 13 '16 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.