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:
* * * * * /path/to/main_script.sh
#!/bin/sh mins=$[ $(date +%s) / 60 ] # current time, rounded to minutes run_1min_task.sh if [ $[ $mins % 10 ] -eq 0 ] ; then # mins divisible by 10 ? run_10min_task.sh # run the every 10 min task fi if [ $[ $mins % 60 ] -eq 0 ] ; then # same for 1 hour run_1hour_task.sh fi if [ $[ $mins % 1440 ] -eq 0 ] ; then # 1440 = 24*60 run_daily_task.sh fi
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.