LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Crontab time question (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-time-question-556518/)

thetawaverider 05-24-2007 09:13 PM

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

wjevans_7d1@yahoo.co 05-24-2007 09:33 PM

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.

michaelk 05-24-2007 09:39 PM

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

thetawaverider 05-24-2007 10:30 PM

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


All times are GMT -5. The time now is 04:07 PM.