LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 04-23-2010, 03:37 AM   #16
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957

Ok. Indeed, I never considered an interval which is not a common divisor of 60. Just out of curiosity I tried the crontab on my system and it runs at 00 and at 59 minutes of every hour! It looks like cron starts the count at 00 minutes in any case and applies as many intervals as they fit in one hour. Does it work like this on your system? Thanks.
 
Old 04-26-2010, 02:40 PM   #17
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by colucix View Post
Ok. Indeed, I never considered an interval which is not a common divisor of 60. Just out of curiosity I tried the crontab on my system and it runs at 00 and at 59 minutes of every hour! It looks like cron starts the count at 00 minutes in any case and applies as many intervals as they fit in one hour. Does it work like this on your system? Thanks.
Yes!

Besides, those who think

Code:
<time fields> sleep 30; someOtherCommandOrScript
would execute the command every 30 seconds, don't seem to have tried it really. Because, when sleep 30 would cause the next command to be delayed for 30 seconds! So, there would be delay of 90 seconds!

So, logically, I have not yet figured out how to shcedule a job to be executed every 30 seconds.

Last edited by Hi_This_is_Dev; 04-26-2010 at 02:43 PM.
 
Old 04-28-2010, 04:20 AM   #18
Dralnu
Member
 
Registered: Jul 2005
Distribution: Arch Linux, Gentoo Linux
Posts: 335

Rep: Reputation: Disabled
Quote:
Originally Posted by Hi_This_is_Dev View Post
Yes!

Besides, those who think

Code:
<time fields> sleep 30; someOtherCommandOrScript
would execute the command every 30 seconds, don't seem to have tried it really. Because, when sleep 30 would cause the next command to be delayed for 30 seconds! So, there would be delay of 90 seconds!

So, logically, I have not yet figured out how to shcedule a job to be executed every 30 seconds.
My bash is a little rusty, so here is one method:

Write up a script/function to do what you want, then execute said script in the background, store the PID to a variable, then run sleep. At the end of of sleep run wait PID to see if the process finished. If it has not it will wait until that script has executed before continuing. You could also use pgrep to check to see if the process exist anymore, which would allow you to simply loop over the sleep command in a way such as (again, rusty from memory bash here):

Code:
while true; do
   sleep 60
   a=$(pgrep PID)
   if (( a == "1" )); then # 1 is the return value of pgrep when no processes match
      run_script_again
      Store_pid_again
   fi
done
That is just an example of course, but you should get the idea. That should prevent the process running several times at once while timing the process to run every 60 seconds. You could do something similar with cron, simply checking for the process before executing it via pgrep or some other method.

EDIT:

Wouldn't
<time fields> sleep 30; command
execute sleep 30; command every second, simply delaying the execution of the command but actually running the line every second?

Last edited by Dralnu; 04-28-2010 at 04:22 AM.
 
Old 04-28-2010, 01:52 PM   #19
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Wouldn't
<time fields> sleep 30; command
execute sleep 30; command every second, simply delaying the execution of the command but actually running the line every second?
Well, I think, when I checked it it was executing every minute instead.
 
  


Reply

Tags
analysis, as, column, could, crontab, experience, ie, isnt, second, seconds, star


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bad minute error adding a crontab job htamayo Linux - Newbie 7 03-15-2010 09:56 AM
the crontab job is not run ust Linux - Software 1 03-24-2008 08:03 PM
Run crontab job sunhui Linux - Software 2 05-16-2007 09:35 PM
want to run program every minute, crontab???? poj Linux - General 4 09-19-2005 05:29 PM
schedule job to be run at 8:00pm every night ashley75 Linux - General 22 10-24-2003 01:44 PM


All times are GMT -5. The time now is 04:51 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration