How would I get a cron job to run every 30 minutes?

前端 未结 6 1216
鱼传尺愫
鱼传尺愫 2020-12-04 07:36

I\'m looking to add a crontab entry to execute a script every 30 minutes, on the hour and 30 minutes past the hour or something close. I have the following, but

相关标签:
6条回答
  • 2020-12-04 07:46

    If your cron job is running on Mac OS X only, you may want to use launchd instead.

    From Scheduling Timed Jobs (official Apple docs):

    Note: Although it is still supported, cron is not a recommended solution. It has been deprecated in favor of launchd.

    You can find additional information (such as the launchd Wikipedia page) with a simple web search.

    0 讨论(0)
  • 2020-12-04 07:46

    You can use both of ',' OR divide '/' symbols.
    But, '/' is better.
    Suppose the case of 'every 5 minutes'. If you use ',', you have to write the cron job as following:

    0,5,10,15,20,25,30,35,....    *      *     *   * your_command
    

    It means run your_command in every hour in all of defined minutes: 0,5,10,...

    However, if you use '/', you can write the following simple and short job:

    */5  *  *  *  *  your_command
    

    It means run your_command in the minutes that are dividable by 5 or in the simpler words, '0,5,10,...'

    So, dividable symbol '/' is the best choice always;

    0 讨论(0)
  • 2020-12-04 07:48

    Do:

    0,30 * * * * your_command
    
    0 讨论(0)
  • 2020-12-04 07:51

    You mention you are using OS X- I have used cronnix in the past. It's not as geeky as editing it yourself, but it helped me learn what the columns are in a jiffy. Just a thought.

    0 讨论(0)
  • 2020-12-04 07:52

    Try this:

    0,30 * * * * your command goes here
    

    According to the official Mac OS X crontab(5) manpage, the / syntax is supported. Thus, to figure out why it wasn't working for you, you'll need to look at the logs for cron. In those logs, you should find a clear failure message.

    Note: Mac OS X appears to use Vixie Cron, the same as Linux and the BSDs.

    0 讨论(0)
  • 2020-12-04 07:55

    crontab does not understand "intervals", it only understands "schedule"

    valid hours: 0-23 -- valid minutes: 0-59

    example #1

    30 * * * * your_command

    this means "run when the minute of each hour is 30" (would run at: 1:30, 2:30, 3:30, etc)

    example #2

    */30 * * * * your_command

    this means "run when the minute of each hour is evenly divisible by 30" (would run at: 1:30, 2:00, 2:30, 3:00, etc)

    example #3

    0,30 * * * * your_command

    this means "run when the minute of each hour is 0 or 30" (would run at: 1:30, 2:00, 2:30, 3:00, etc)

    it's another way to accomplish the same results as example #2

    example #4

    19 * * * * your_command

    this means "run when the minute of each hour is 19" (would run at: 1:19, 2:19, 3:19, etc)

    example #5

    */19 * * * * your_command

    this means "run when the minute of each hour is evenly divisible by 19" (would run at: 1:19, 1:38, 1:57, 2:19, 2:38, 2:57 etc)

    note: several refinements have been made to this post by various users including the author

    0 讨论(0)
提交回复
热议问题