LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2011, 09:57 AM   #1
deeppal123
LQ Newbie
 
Registered: Feb 2011
Posts: 10

Rep: Reputation: 0
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.
 
Old 03-17-2011, 10:39 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,249

Rep: Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431
Quote:
Originally Posted by deeppal123 View Post
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.
This, along with your other posts, sound VERY much like homework.

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.
 
Old 03-17-2011, 11:38 AM   #3
m_kane
Member
 
Registered: Jan 2009
Posts: 31

Rep: Reputation: 2
Quote:
Originally Posted by deeppal123 View Post
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.
Can't you schedule them to run different time if you want them to run in specific order? Eg. second job a minute later that first.
Other way is to create script which run jobs in specific order and then put that script to crontab.

Last edited by m_kane; 03-17-2011 at 11:39 AM.
 
Old 03-18-2011, 12:31 AM   #4
deeppal123
LQ Newbie
 
Registered: Feb 2011
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 03-18-2011, 11:02 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,249

Rep: Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431Reputation: 4431
Quote:
Originally Posted by deeppal123 View Post
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.
Spell out your words, and write clearly. And having not posted to one of your questions before, I don't 'remember' you doing follow up work, but just see what you posted in your threads.

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:
  • Find a file location in current directory(recursive directory) without using find command.
  • how to find all child processes of a parent process given to script as argument. i would like to know the methodology as well as approach.
And this thread. The questions are very homework-like, especially since in a real-world environment, why WOULDN'T you be able to use find? Why would you need to write a script to find child processes, when you can type "ps" at a command-prompt? (these things don't come up in production environments).??

Last edited by TB0ne; 03-18-2011 at 11:06 AM.
 
1 members found this post helpful.
Old 03-18-2011, 11:40 AM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
Quote:
Originally Posted by TB0ne View Post
This, along with your other posts, sound VERY much like homework.

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.
I think what he is asking, which i have to say was hard to tell at first, is that, assuming:

* 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?

Last edited by szboardstretcher; 03-18-2011 at 11:42 AM.
 
Old 03-18-2011, 11:45 AM   #7
vonedaddy
Member
 
Registered: Aug 2004
Location: Philadelphia,PA
Posts: 180

Rep: Reputation: 17
Quote:
Originally Posted by szboardstretcher View Post
I think what he is asking, which i have to say was hard to tell at first, is that, assuming:

* 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?
I believe they would all run at the same time. There is no reason multiple processes could not be launched at the exact same time.
 
Old 03-18-2011, 11:47 AM   #8
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
Quote:
Originally Posted by vonedaddy View Post
I believe they would all run at the same time. There is no reason multiple processes could not be launched at the exact same time.
According to /var/log/cron, and a little test I just ran, with 3 scripts just like above...

It says that they are running from the Top Down.
 
1 members found this post helpful.
Old 03-18-2011, 02:40 PM   #9
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 195

Rep: Reputation: 50
Quote:
Originally Posted by szboardstretcher View Post
According to /var/log/cron, and a little test I just ran, with 3 scripts just like above...

It says that they are running from the Top Down.
Are you sure they are just not logged in order? Fora test put a sleep in the first script and see if it gets logged last.
 
Old 03-22-2011, 01:00 AM   #10
deeppal123
LQ Newbie
 
Registered: Feb 2011
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 03-22-2011, 02:16 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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.
 
Old 03-22-2011, 09:08 AM   #12
deeppal123
LQ Newbie
 
Registered: Feb 2011
Posts: 10

Original Poster
Rep: Reputation: 0
@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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Cron job Zango Debian 1 03-29-2010 01:12 PM
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 09:52 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron job Thulemanden Linux - General 1 11-06-2006 12:40 PM
cron job sanjith11 Linux - General 5 07-14-2004 02:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration