LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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-14-2010, 05:27 PM   #1
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

Rep: Reputation: 18
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"?
 
Old 04-14-2010, 05:42 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Yes it does, for every minute use "*" in the first position
 
Old 04-14-2010, 06:48 PM   #3
dnaqvi
Member
 
Registered: Oct 2009
Posts: 117

Rep: Reputation: 15
Quote:
Originally Posted by kbp View Post
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?
 
Old 04-14-2010, 07:02 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

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

cheers
 
Old 04-14-2010, 09:31 PM   #5
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 dnaqvi View Post
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!
 
Old 04-15-2010, 12:13 PM   #6
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
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
 
Old 04-15-2010, 02:58 PM   #7
\\.\
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Rep: Reputation: 0
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.
 
Old 04-15-2010, 03:53 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Hi_This_is_Dev View Post
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...
 
Old 04-15-2010, 04:32 PM   #9
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 \\.\ View Post
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.
 
Old 04-15-2010, 04:37 PM   #10
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 TB0ne View Post
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.
 
Old 04-15-2010, 04:53 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Hi_This_is_Dev View Post
"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.
 
Old 04-16-2010, 01:02 AM   #12
\\.\
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Rep: Reputation: 0
Quote:
Originally Posted by Hi_This_is_Dev View Post
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.
 
Old 04-19-2010, 03:25 PM   #13
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 \\.\ View Post
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."
 
Old 04-19-2010, 03:46 PM   #14
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Code:
*/59 * * * * /root/bin/at60.sh
That would run the script every minute (or 59 seconds.)
Do you mean "every 59 minutes"!?!
 
Old 04-22-2010, 06:24 PM   #15
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
Lightbulb

Quote:
Originally Posted by colucix View Post
Do you mean "every 59 minutes"!?!
Yes!
 
  


Reply

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



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 08:56 AM
the crontab job is not run ust Linux - Software 1 03-24-2008 07:03 PM
Run crontab job sunhui Linux - Software 2 05-16-2007 08:35 PM
want to run program every minute, crontab???? poj Linux - General 4 09-19-2005 04:29 PM
schedule job to be run at 8:00pm every night ashley75 Linux - General 22 10-24-2003 12:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:53 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
Open Source Consulting | Domain Registration