两个问题:Crontabs 和文件覆盖

两个问题:Crontabs 和文件覆盖

为什么当我在 crontab 上使用此行时会出现错误?

线:0 1/2 * * * cd public_html/wp-content/plugins && ./16134.bash

错误:errors in crontab file, can't install.

我已经创建了这条线http://crontab.guru/帮助,但是它不起作用,我想让 crontab 在 1、3、5、7、9、11、13、15、17、19、21 和 23 小时的第 0 分钟执行命令。

像这样的行确实有效:0 */2 * * * cd public_html/wp-content/plugins && ./16134.bash

另外,现在,为了替换文件的数据,我使用这个组合,首先清空文件cat/dev/null>16134.txt,其次,将 py 输出的内容添加到文件中./16134.py >> 16134.txt。问题是,当我运行这些命令时,在清空文件后,python 执行需要 2-5 秒,因此文件在这 2-5 秒内是空白的,这使得我的网站上的输出也是空白的,所以这就是为什么找到替代方案会很好。

感谢您的阅读,如能提供任何帮助我将不胜感激。

答案1

man 5 crontab

Step values can be used in conjunction with ranges.  Following a range with
``/<number>'' specifies skips of the number's value through the range.  For
example, ``0-23/2'' can be used in the hours field to specify command
execution every other hour (the alternative in the V7 standard is
``0,2,4,6,8,10,12,14,16,18,20,22''). Steps are also permitted after an
asterisk, so if you want to say ``every two hours'', just use ``*/2''.

因此/2必须遵循一系列值。在您的例子中,您希望在 1-23 范围内每隔一小时运行一次命令,这样1-23/2就可以了。

相关内容