cron job
a job1 is registered first and job2 is registered second in crontab. But when scheduled time is reached, job2 is executed first and job1 is executed second.
Please can anyone give any possible reason of second registered job being executed first instead of first registered job. |
Quote:
You say 'registered'...what do you mean? The only way cron will execute jobs, is by chronological order. If Job2 is scheduled to run at 7 AM, and job1 at 8 AM, then that's what they'll do, regardless of the order in which they're 'registered' in cron. If they're both scheduled at the same time, one may take a longer time to fire up a command/query/whatever than the other, so things may not start processing at exactly the same time. |
Quote:
Other way is to create script which run jobs in specific order and then put that script to crontab. |
well i am new to linux,so obviously questions can seem to be homework.but if u remember clearly there was a lot of follow up work that i did after querying.
|
Quote:
And I'm sorry, but the questions you've posted are written as if they were homework assignments, described as if they were, and ask questions that would be in many, many, courses. For example:
|
Quote:
* 5 * * * /scripts/go.sh * 5 * * * /scripts/go3.sh * 5 * * * /scripts/go2.sh What order will they run in. And the answer is.... No idea. Random? |
Quote:
|
Quote:
It says that they are running from the Top Down. |
Quote:
|
well i just did something like this
5 * * * * echo 1 >/home/temp/abc.txt 5 * * * * echo 2>/home/temp/abc.txt and followd it up wd same kind of jobs.Now thing is when i change the time,the first job is not being executed first,instead jobs are executing randomly.one thing is at a given time,only one job can be executed,but is there any way where we can specify the order in which jobs are going to be executed? like the first job gets executed first and so on,instead of some random job getting executed. |
cron is designed to try and launch jobs as close as possible to their requested times in the crontab file(s). If multiple jobs are requested to run with the SAME time params, then the order is undefined (to within a small time period).
This goes double for multi-core systems. The internal src code likely does it in the order specified in the crontab. Unless you are measuring down to extremely fine levels, this is not likely to be evident. If you REALLY need jobs to be run in a specific order, have one job call another. Do NOT rely on crontab order. You MAY use a time difference to separate the jobs, IF you can guarantee that job1 will finish within the time allowed before job2 commences. |
@vonedaddy----> yes it works fine and accordin to the order the commands are enlisted in the shell script and then on putting the shell script in the cron tab it works just fine.thanks a lot for helping out.
|
All times are GMT -5. The time now is 09:59 AM. |