Find the answer to your Linux question:
Results 1 to 8 of 8
I have the below crontab job that it will run at every 7:00am - 10:00am , it work fine , now if I want to skip to run the crontab ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    ust
    ust is offline
    Just Joined!
    Join Date
    Feb 2005
    Posts
    77

    Run cron job problem


    I have the below crontab job that it will run at every 7:00am - 10:00am , it work fine , now if I want to skip to run the crontab job at a specific time , eg. I want the script not to run at next Monday 8:00am ( only skip this time , other time is normal ) , how can I make it ? is it possible ? thx in advance .


    00 7-10 * * * script

  2. #2
    Linux User
    Join Date
    Feb 2005
    Posts
    290
    use at command to instruct your server to stop crond one minute before next Monday 8:00am and restart crond at 8:01am, or make your script to kill itself if it is "Monday 8:00am"

    good luck

  3. #3
    ust
    ust is offline
    Just Joined!
    Join Date
    Feb 2005
    Posts
    77
    thx reply ,

    but if do so , the other process also can't run at Monday 08:00 , I think it is not suit to my case as we have many cronjob that that time , is there other advice ? thx

  4. #4
    Linux Enthusiast
    Join Date
    Feb 2005
    Location
    SE, Stockholm
    Posts
    512
    Your crontab should look like something like this
    Code:
    0 7-10 * * 0,2,3,4,5,6,7  script
    The time columns is:

    Minutes 0-59
    Hours 0-23
    Day of month 1-31
    Month 1-12
    Day of week 0-6 (0 == Sunday by default)

  5. #5
    Linux User
    Join Date
    Feb 2005
    Posts
    290
    Quote Originally Posted by swemic
    Your crontab should look like something like this
    Code:
    0 7-10 * * 0,2,3,4,5,6,7  script
    then it will do nothing on every monday !



    try this at the beginning of your script:
    Code:
    #!/bin/sh
    day=`date | awk '{print $1}'`
    time=`date | awk '{print substr($4,0,2)}'`
    echo $time
    if [ $day = "Mon" ]; then
      if [$time = "08" ]; then
        exit
      fi
    fi
    excuse me for my bad scripting, but that should give you some ideas, you might want to check for date as well

    good luck

  6. #6
    Linux Enthusiast
    Join Date
    Feb 2005
    Location
    SE, Stockholm
    Posts
    512
    then it will do nothing on every monday !
    And that's exactly whats wanted, right? It was just this particular script that was not supposed to be started each monday,
    Code:
    0 1 * * * script1
    0 2 * * 0,2,4 script2
    This crontab will run script1 every day at 1:00 am,
    and script2 every Sun, Tue, Thu at 2:00 am.

    Just to fast I was, saw a flaw in my prev example,
    should have been:
    Code:
     0 7-10 * * 0,2,3,4,5,6 script
    The last 7 would be erreneous

  7. #7
    Linux User
    Join Date
    Feb 2005
    Posts
    290

    Re: Run cron job problem

    Quote Originally Posted by ust
    eg. I want the script not to run at next Monday 8:00am ( only skip this time , other time is normal )
    my understanding is the cron should only skip next Monday's 8:00am, the rest of the Monday 8:00am is not included.... hmm....

    whatever...

  8. #8
    Linux Enthusiast
    Join Date
    Feb 2005
    Location
    SE, Stockholm
    Posts
    512
    Could be, I might have missunderstand the context of the question.
    Even so, there are a few solutions here now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •