LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   crontab - schedule job to run every minute (https://www.linuxquestions.org/questions/linux-general-1/crontab-schedule-job-to-run-every-minute-802052/)

Hi_This_is_Dev 04-14-2010 05:27 PM

crontab - schedule job to run every minute
 
I am setting crontab to run a script every minute irrespective of the current hour's value:

Code:

[root@localhost bin]# ls
sec.php  showTime.sh
[root@localhost bin]# crontab -l
1 * * * * /root/bin/showTime.sh

[root@localhost bin]#

But it is not working. :(

Any solutions? Does the line mean: "Run this script every day at hour:01"?

kbp 04-14-2010 05:42 PM

Yes it does, for every minute use "*" in the first position

dnaqvi 04-14-2010 06:48 PM

Quote:

Originally Posted by kbp (Post 3935735)
Yes it does, for every minute use "*" in the first position

What should be for every hour?

and

What should be for after every 12 hour?

kbp 04-14-2010 07:02 PM

Probably easier if you check out some examples : http://adminschoice.com/crontab-quick-reference

cheers

Hi_This_is_Dev 04-14-2010 09:31 PM

Quote:

Originally Posted by dnaqvi (Post 3935788)
What should be for every hour?

and

What should be for after every 12 hour?


Before I would check my post here, I had got the solution. I asked an Admin of UNIX here and he told me that *would be used "for every minute".

*/5 means every 5 minutes.

Code:

*/5 * * * * /root/bin/showTime.sh
So, for every hour it should be:

Code:

  */60 * * * * /root/bin/showTime.sh
and for every 12 hour:

Code:

  */60 */12 * * * /root/bin/showTime.sh
/n is the step value

I am going to put those lines in my crontab and will check the output when I come to office tonight. My shift is over. I am going now!

Hi_This_is_Dev 04-15-2010 12:13 PM

For jobs to be run every 12 hour, this crontab entry didn't execute at all:

Code:

*/60 */12 * * * /root/bin/showTime.sh
So, now I am setting this one:

Code:

* */12 * * * /root/bin/at12.sh

\\.\ 04-15-2010 02:58 PM

If this is on your local machine and not a remote server, you could be lazy and use a GUI called Gnome Schedule to set up the task for you.

According to the GUI, you need * * * * * 's to run a task every minute.

TB0ne 04-15-2010 03:53 PM

Quote:

Originally Posted by Hi_This_is_Dev (Post 3935728)
I am setting crontab to run a script every minute irrespective of the current hour's value:

Code:

[root@localhost bin]# ls
sec.php  showTime.sh
[root@localhost bin]# crontab -l
1 * * * * /root/bin/showTime.sh

[root@localhost bin]#

But it is not working. :(

Any solutions? Does the line mean: "Run this script every day at hour:01"?

That's a dangerous thing to do, since CRON will have to fire up, and run your script. If it runs more than 1 minute, you'll then have TWO running...etc, .etc......

Why not just run the script one time (system startup?), and put a "sleep 60" statement in it, and loop back to the beginning?? That way, even if it takes 5 minutes to execute, it'll finish ONE loop, sleep 60 seconds, then run again, instead of cranking off 5 fresh copies...

Hi_This_is_Dev 04-15-2010 04:32 PM

Quote:

Originally Posted by \\.\ (Post 3936826)
If this is on your local machine and not a remote server, you could be lazy and use a GUI called Gnome Schedule to set up the task for you.

According to the GUI, you need * * * * * 's to run a task every minute.


GUI is for kids! No matter how many key strokes a command or task may require, I would prefer the old command line interface or console.

Well, I am using PUTTY to login remotely on the server.

Hi_This_is_Dev 04-15-2010 04:37 PM

Quote:

Originally Posted by TB0ne (Post 3936888)
That's a dangerous thing to do, since CRON will have to fire up, and run your script. If it runs more than 1 minute, you'll then have TWO running...etc, .etc......

Why not just run the script one time (system startup?), and put a "sleep 60" statement in it, and loop back to the beginning?? That way, even if it takes 5 minutes to execute, it'll finish ONE loop, sleep 60 seconds, then run again, instead of cranking off 5 fresh copies...

"system startup": that would require the system or server to bed rebooted at least once after a script has been scheduled to be executed at Startup.

Well, in production servers we cannot reboot servers like that. Besides, running a job every minute is not what we (or at least I) would do. It is just a problem!

Anyways, I have done it.


Code:

*/59 * * * * /root/bin/at60.sh
That would run the script every minute (or 59 seconds.) In fact, I tried

Code:

*/60 * * * * /root/bin/at60.sh
as well. It too worked. But the value that can come there should be 0-59.

TB0ne 04-15-2010 04:53 PM

Quote:

Originally Posted by Hi_This_is_Dev (Post 3936936)
"system startup": that would require the system or server to bed rebooted at least once after a script has been scheduled to be executed at Startup.

Was a *SUGGESTION*, and NOT the only way to run a script.
Quote:

Well, in production servers we cannot reboot servers like that. Besides, running a job every minute is not what we (or at least I) would do. It is just a problem!
You don't have to...it's a SCRIPT, just run it. However you choose to...command line, rc.local, whatever.
Quote:

Anyways, I have done it.
Congratulations...the first time the script takes over 60 seconds to process, enjoy the results.

\\.\ 04-16-2010 01:02 AM

Quote:

Originally Posted by Hi_This_is_Dev (Post 3936931)
GUI is for kids! No matter how many key strokes a command or task may require, I would prefer the old command line interface or console.

Well, I am using PUTTY to login remotely on the server.

So I'M a 42 year old kid then, thanks for that.

We all have to start somewhere and if Linux was not so fiddly and picky, it may have a chance at kicking windows off the top slot... but it isn't.

As for the comment, it was only a suggestion to solve a problem quickly, sometimes the method or means of performing a task are less important than the actual outcome.

Hi_This_is_Dev 04-19-2010 03:25 PM

Quote:

Originally Posted by \\.\ (Post 3937209)
So I'M a 42 year old kid then, thanks for that.

We all have to start somewhere and if Linux was not so fiddly and picky, it may have a chance at kicking windows off the top slot... but it isn't.

As for the comment, it was only a suggestion to solve a problem quickly, sometimes the method or means of performing a task are less important than the actual outcome.



I respect your age and experience, sir. Please, don't mind my comment. I am sometimes a kind of "showing-humour".

Well, I agree to what you have said:

Quote:

"Sometimes the method or means of performing a task are less important than the actual outcome."

colucix 04-19-2010 03:46 PM

Quote:

Code:

*/59 * * * * /root/bin/at60.sh
That would run the script every minute (or 59 seconds.)
Do you mean "every 59 minutes"!?! :confused:

Hi_This_is_Dev 04-22-2010 06:24 PM

Quote:

Originally Posted by colucix (Post 3940734)
Do you mean "every 59 minutes"!?! :confused:

Yes!


All times are GMT -5. The time now is 02:44 PM.