Cron Bad Minute Error: “home.cron”:0: bad minute c

2019-08-13 08:44发布

问题:

I am creating the cron on Mac OS Terminal, here is the code:

contents of home.cron:

* * * * * /users/username/desktop/forTrump/script.sh

then I run it like this:

crontab home.cron

then I get this error:

"home.cron":0: bad minute crontab: errors in crontab file, can't install

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.

回答1:

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.

However in your posted home.cron the path is wrong.

This:

* * * * * /users/username/desktop/forTrump/script.sh 

should be:

* * * * * /Users/username/Desktop/forTrump/script.sh

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

To install that script as root first switch to root like this:

sudo su

followed by:

crontab home.cron

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

See also: https://www.dougv.com/2006/12/fixing-a-bad-minute-error-message-when-trying-to-use-crontab-with-certain-unix-text-editors/

This problem most often occurs because you’re using a text editor, such as pico, that fakes word wrapping by adding a newline when it reaches a certain column position.

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.

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.



回答2:

I have encountered with similar issue today: "/tmp/crontab.vjQAiZ" 1L, 14C written crontab: installing new crontab "/tmp/crontab.vjQAiZ":0: bad minute errors in crontab file, can't install. Do you want to retry the same edit?

Same error was raised even I tried to add ABSOLUTELY correct entry in my crontab list. As usual I have leart google advices. But notihng has helped.

The solution in my case: 100% usage of /var/log/ directory. It looks like cron can't update own logs and therefore writes similar error when you would like to save your changes.

When I deleted extra log files, issue was solved.

Good luck!



回答3:

This error (especially if the error indicates that the invalid minute is at column 0) will also occur if the volume where cron files are stored is out of space.



回答4:

When exactly shall your cron job run - every minute?

m h dom mon dow command
*/1 * * * *  /users/username/desktop/againstTrump/script.sh


标签: shell cron