LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2007, 10:13 PM   #1
thetawaverider
Member
 
Registered: Feb 2006
Distribution: CentOS
Posts: 47

Rep: Reputation: 15
Crontab time question


Hi,

Can someone tell me if it's possible to run a crontab script only on an odd or even minute? I need so split some jobs so that some run at 1:01, 1:03, etc., while the others run 1:02, 1:04, etc.

Thanks,
TWR
 
Old 05-24-2007, 10:33 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
You can get pretty close to it. First, install somewhere this script I just whipped up. Let's say it's at /bin/evenodd:

Code:
#!/bin/sh

whichone=$1

shift

second=$(date '+%S' | sed -e 's/^.//')

if echo $second | grep [02468] > /dev/null
then
  if [ $whichone = "even" ]
  then
    "$@"
  fi
else
  if [ $whichone = "odd" ]
  then
    "$@"
  fi
fi
Then in your crontab file instead of executing this program:

Code:
/usr/bin/whatever the chosen parameters
you execute this program if you want it to run at even-numbered seconds:

Code:
/bin/evenodd even /usr/bin/whatever the chosen parameters
or this program if you want it to run at odd-numbered seconds:

Code:
/bin/evenodd odd /usr/bin/whatever the chosen parameters
Hope this helps.
 
Old 05-24-2007, 10:39 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,937

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Yes, Check out the man pages for crontab. There is an example of how to run a script every other minute. Not trying to make this an RTFM answer but how to think and search first.

http://www.rt.com/man/crontab.5.html

Last edited by michaelk; 05-24-2007 at 10:52 PM.
 
Old 05-24-2007, 11:30 PM   #4
thetawaverider
Member
 
Registered: Feb 2006
Distribution: CentOS
Posts: 47

Original Poster
Rep: Reputation: 15
It wasn't so much a matter of every other minute (easy w/ */2 for minute column), but on even OR on odd minutes. Thank you, though, for the man pointer (I did look but in the wrong one). Here are two examples that do just what I want:

Code:
0-58/2 * * * * /bin/myscript
1-59/2 * * * * /bin/myscript
TWR
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab time afbase Linux - Newbie 5 12-31-2006 10:34 PM
crontab question mmoor Fedora 5 05-20-2006 04:50 PM
crontab 24-hour time cleopard Linux - General 2 05-09-2006 08:24 AM
skip the crontab job for one time ust Linux - General 2 04-20-2005 04:01 AM
Crontab question mikeshn Linux - General 3 09-06-2003 07:26 PM


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