问题描述
我正在Mac OS Terminal上创建cron,下面是代码:
I am creating the cron on Mac OS Terminal, here is the code:
home.cron
:
* * * * * /users/username/desktop/forTrump/script.sh
然后我像这样运行它:
crontab home.cron
然后我得到此错误:
这是上面打开的外壳文件,我测试了一下,可以通过在OS终端上执行 ./ script.sh
来完美运行,但是我可以似乎没有在 cron
中运行它而没有得到该错误。
Here is the shell file that is opened above, I tested and this runs perfectly by executing ./script.sh
from os terminal but I can't seem to run it in cron
w/o getting that error.
#!/bin/sh
python /Users/username/Desktop/forTrump/test.py
我已经确保没有换行符导致分钟错误,谢谢您的帮助。
I already ensure that there were no line breaks causing the bad minute error, thanks in advance for your help.
推荐答案
雅高都与 crontab.guru
都和本质上是相同的,尽管您可能想尝试其他方法,以防万一您的系统没有
According to crontab.guru
both * * * * *
and *\1 * * * *
are essentially the same thing although you may want to try the alternative just in case your system does not like one or the other.
但是在您发布的 home.cron
中,路径是错误的。
However in your posted home.cron
the path is wrong.
此:
* * * * * /users/username/desktop/forTrump/script.sh
应为:
* * * * * /Users/username/Desktop/forTrump/script.sh
但是,如果脚本需要提升的特权,则需要使用root crontab和由于在这样的命令之前添加了用户列,因此使用的行略有不同:
However if the script requires elevated privileges then you will need to use the root crontab and the line used is slightly different due to the addition of a user column before the command like this:
* * * * * root /Users/username/Desktop/forTrump/script.sh
要安装作为根用户的hat脚本首先要像这样切换到根用户:
To install that script as root first switch to root like this:
sudo su
之后:
crontab home.cron
还要看到您在Mac OS X上,请确保 home.cron
中的行以 \终止\n
而不是 \r
或 \n\r
Also seeing you are on Mac OS X make sure the line in home.cron
is terminated with just \n
and not \r
or \n\r
另请参阅:
Crontab用换行符(换行符)分隔作业。每个工作占用一行。因此,如果crontab在一行的第一列中看到除整数以外的任何内容,则它将引发糟糕的分钟错误,因为分钟参数是crontab遇到的第一个参数。
Crontab delimits jobs with line breaks (newlines). Each job occupies one line. Therefore, if crontab sees anything other than an integer in the first column of a line, it throws the "bad minute" error, since the minute argument is the first one crontab encounters.
一个简单的解决方法是删除pico /您的* nix编辑器添加的换行符。您可以最轻松地做到这一点,方法是将光标放在每行的第一个字符上,然后按退格键,直到该行与上一行连接在一起,然后重复此过程,直到整个cron命令都在一行上。
The simple fix is to go to delete the line breaks added by pico / your *nix editor. You can most easily do that by putting your cursor on the first character of each extra line, then hit the backspace key until that line is joined back up with the previous one, and repeating the process until your entire cron command is on one line.
这篇关于Cron错误的分钟错误:“ home.cron”:0:错误的分钟crontab:crontab文件中的错误,无法安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!