每 6 小时在 linux 上运行一次 cron 作业
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11562804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running cron job on linux every 6 hours
提问by Gandalf StormCrow
How can I run command every six hours every day? Tried this not working :
如何每天每六个小时运行一次命令?试过这个不起作用:
/6 * * * * * mycommand
采纳答案by nos
You forgot a *
,and you've too many fields, and it's the hour you need to care about
你忘记了*
,你的领域太多了,这是你需要关心的时间
0 */6 * * * /path/to/mycommand
This means every 6th hour starting from 0, i.e. at hour 0, 6, 12 and 18 Which you could write as
这意味着从 0 开始每 6 小时,即在小时 0、6、12 和 18,您可以写为
0 0,6,12,18 * * * /path/to/mycommand
回答by Brian Agnew
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.
您应该包含命令的路径,因为 cron 在一个广泛缩减的环境中运行。您不会拥有交互式 shell 会话中的所有环境变量。
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.
指定脚本/二进制文件的绝对路径,或在 crontab 本身中定义 PATH 是个好主意。为了帮助调试任何问题,我还将 stdout/err 重定向到日志文件。
回答by rkoots
0 */6 * * * command
This will be the perfect way to say 6hrs a day.
这将是一天 6 小时的完美表达方式。
Your command puts for 6 mins!
您的命令持续 6 分钟!
回答by Nilesh Patil
0 */6 * * *
crontab every 6 hours is a commonly used cron schedule.
crontab 每 6 小时是一个常用的 cron 计划。
回答by rkoots
Try:
尝试:
0 */6 * * * command
. * has to
. * 不得不
回答by rkoots
You need to use *
您需要使用 *
0 */6 * * * /path/to/mycommand
Also you can refer https://crontab.guru/which will help you in scheduling better...
您也可以参考https://crontab.guru/这将帮助您更好地安排时间...
回答by Andrea Bisello
Please keep attention at this syntax
请注意这个语法
* */6 * * *
this mean 60 TIMES (Every minutes) every 6 hours
这意味着每 6 小时 60 次(每分钟)
not
不是
one time every 6 hours.
每 6 小时 1 次。
this answer can be a comment, but the danger is too high so i proposed to add a new answer. If community will downgrade my answer i will remove and put as a comment.
这个答案可以是评论,但危险性太高,所以我建议添加一个新答案。如果社区将我的答案降级,我将删除并作为评论。