Running a cron job on Linux every six hours

后端 未结 7 680
旧巷少年郎
旧巷少年郎 2020-11-29 19:32

How can I run command every six hours every day?

I tried the following, but it did not work:

/6 * * * * *  mycommand
相关标签:
7条回答
  • 2020-11-29 19:38

    You need to use *

    0 */6 * * * /path/to/mycommand
    

    Also you can refer to https://crontab.guru/ which will help you in scheduling better...

    0 讨论(0)
  • 2020-11-29 19:40
    0 */6 * * * command
    

    This will be the perfect way to say 6 hours a day.

    Your command puts in for six minutes!

    0 讨论(0)
  • 2020-11-29 19:43

    You should include a path to your command, since cron runs with an extensively cut-down environment. You won't have all the environment variables you have in your interactive shell session.

    It's a good idea to specify an absolute path to your script/binary, or define PATH in the crontab itself. To help debug any issues I would also redirect stdout/err to a log file.

    0 讨论(0)
  • You forgot a *, and you've too many fields. It's the hour you need to care about

    0 */6 * * * /path/to/mycommand
    

    This means every sixth hour starting from 0, i.e. at hour 0, 6, 12 and 18 which you could write as

    0 0,6,12,18 * * * /path/to/mycommand
    
    0 讨论(0)
  • 2020-11-29 19:55
    0 */6 * * *
    

    crontab every 6 hours is a commonly used cron schedule.

    0 讨论(0)
  • 2020-11-29 19:56

    Please keep attention at this syntax:

    * */6 * * *
    

    This means 60 times (every minute) every 6 hours,

    not

    one time every 6 hours.

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