Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, How to run a cron every 2 minu 8

Status
Not open for further replies.

nithin97

Programmer
Oct 23, 2002
25
US
Hi,
How to run a cron every 2 minutes ? and how that cron file has to be saved under what extension ? Thanx....
 
Never edit the cron configuration file manually, use crontab -e to edit your crontab file.

0,2,4,6,8 and so on to ,58 * * * * "your script or command"

where:
1st field = min
2nd field = hour
3rd field = day
4th field = month
5th field = day of the week (0 to 7, 0 and 7 are Sunday)

EDC
 
Every two minutes every day, you'll need a cron entry like:

00,02,04,06,08.......,58 * * * 0-6 /<your script>

to edit the crontab, use crontab -e (an alternative is to edit a separate file then save it and issue a crontab <filename> so that the new file becomes the new crontab). You should be presented with a vi environment (if not do an export EDITOR-vi before editing the file) in which you can enter the baove commands. Then save with a wq! to activate it. Be aware that cron inherits no environment variables, so it may be necessary to add these explicitly if required. For information, I find it easier to add:

#Crontab field order:
#minute (0-59),
#| hour (0-23),
#| | day of the month (1-31),
#| | | month of the year (1-12),
#| | | | day of the week (0-6 with 0=Sunday).
#| | | | | commands

at the top of the crontab so that there is no chance of my getting the various options muddled. HTH.
 
Nice one, nwardez, I hadn't considered the */2 option to run the command every two minutes - worth knowing if only to make the line more readable!
 
Thankx ecasadella, Ken & nwardez... it was really helpful..
 
*/2 doesn't work for me on AIX 4.3.3
:-( Dickie Bird
Honi soit qui mal y pense
 
Dickiebird, must be a Linux thing, first time I have encountered it too, never seen it on AIX. I will try tomorrow on AIX 5.1, maybe I'm lucky.... :-} IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
Damned, I'm unmasked !!!

That's right it doesn't seems to work on both Aix 5.1 & Solaris 8 ... But rmoorthy didn't mention on which *nix he works, Mister Judge. I promise I won't connect back to tek-tips until the end of the week ...
 
FYI rmoorthy;
you can manually create your own cron file following crontab format (as stated by all of our fine forum members above) and save it to the crontab dir (/var/spool/cron/crontab) . That will be read and executed by the cron utility just like any other one.

This is a good practice to keep the system's crontab content at a minimum and reduce the chances of errors that could prevent other cron-jobs from executing.
For example my backup and other cron jobs used to fail due to I edited the crontab wrongly by inserting too many * on a one-liner that calls other utility script.
But when I inserted a cron-file with the one-liner into the crontab dir, a failure in that file does not affect any other cron-job.
^^^^^^^^^^^^^^^^^^^^^^^^^^
Experience is the Best Teacher
But its' cost is Heavy!
^^^^^^^^^^^^^^^^^^^^^^^^^^
 

alternatively you can let your program decide to run or not.
so you once edit crontab.
* * * * * /your/path/exec

put in /your/path/exec

#!/bin/sh
case '/bin/date +%M' in *[13579]) exit 0;; esac
....do the job...
exit 0 -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Hi bkonline, jamisar.... thanks for ur response...
i'll try it...

And Nawardez, I also tried in Solaris 8... its not working... that */2 thing... thanx..
 
Nawardez - this */2 bit makes for a heck of an improvement, wish IBM would incorporate it, it will make cron entries so much tidier.

Thanks for the info, you are welcome back here anytime. IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top