Find the answer to your Linux question:
Results 1 to 4 of 4
Hi All, I have a question regarding running crontab. In one of my Linux box, I need to run a job for every 7 hours. I have tried the below ...
  1. #1
    Just Joined!
    Join Date
    Aug 2007
    Posts
    8

    Running crontab for every 7 hours

    Hi All,

    I have a question regarding running crontab.

    In one of my Linux box, I need to run a job for every 7 hours. I have tried the below method:

    * */7 * * * script.sh

    But here, the job runs at: 0, 7, 14, 21,hours and again at 0 hour on next day. So, After 21 hour the job is suppose to run at 4.00 hour on next day. But it runs at 0.00 hour.

    I know it's possible to write a script to do the same. But I just want to know is there any method to set the cron to run the job at regular intervals.

    Thanks in advance!

    ~Johnson

  2. #2
    Just Joined! adrianx's Avatar
    Join Date
    Feb 2008
    Posts
    27
    Hi,

    I could be wrong, but I think */7 should do what you've described. The only thing that seems wrong is minute=*, it should be:

    0 */7 * * * script.sh

  3. #3
    Just Joined!
    Join Date
    Aug 2007
    Posts
    8
    adrianx,

    Thx for your reply. Yes that was a typo, I never meant that.

    But, regarding */7 I have tested this in my Linux box. As I had informed in my previous post, the job runs at 0, 7, 14, 21,hours and again at 0 hour on next day. So, After 21 hour the job is suppose to run at 4.00 hour on next day. But it runs at 0.00 hour.

    Any solutions appreciated.

    Thanks,
    ~Johnson

  4. #4
    Just Joined!
    Join Date
    Feb 2007
    Posts
    4
    The behavior you're seeing from cron -- running at 0, 7, ... hours and then again with 0, 7, ... the next day -- is what you're supposed to see. AFAIK, there's no way to make cron do what you want.

    You could have cron run your job every hour and have your job check the time before proceeding. Something like this psuedo-code:

    -- get current time
    -- figure total number of hours since some start time
    -- if total hours mod 7 != 0:
    -- exit
    -- start doing real work now

    Rick

Posting Permissions

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