Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254
Original Poster
Rep:
Quote:
Originally Posted by colucix
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 01:43 PM.
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?
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254
Original Poster
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.