crontab 에러

c or linux 2007. 9. 8. 01:31

보통 crontab -e 명령어를 통해서 작업을 하다보면, 다음과 같은 에러가 난다.

 

crontab: installing new crontab
"/tmp/crontab.XXXXScNhd2":3: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit?

 

그 이유는 다음과 같다.

 

문법에 맞는 cron 스타일로 입력하지 않았기 때문에 그런 에러가 나는 것이다.

또는 dos에서 사용되는 ^M$가 라인 뒤에 붙어 있어서 문제가 될 수 도 있다..

 

 

 

 

 

 

* 참고

http://www.linuxboxadmin.com/micro/micro-how%11tos/system-administration/crontab.html

Crontab fields

Here is how the fields are defined:

  1. minute
  2. hour
  3. day of the month
  4. month of the year
  5. day of the week
  6. program or command to run

An asterisk (*) in any field means run every time for this field. Ranges (X-Y) and steps (X-Y/Z) can also be defined.

User crontabs

To edit a user crontab (including root):
crontab -e

To delete a crontab:
crontab -r

System crontab

The system crontab is stored in /etc/crontab. It can be changed (as root) with a text editor.

The system crontab has one extra field before the program to run, which is the user to run the command as (usually root).

Error installing new crontab (bad minute)

I've received this cryptic error message while trying to update a crontab:

crontab: installing new crontab
"/tmp/crontab.XXXXScNhd2":3: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit?

The error message suggests a format problem with my entry, but the real error is due to DOS line endings (CR LF) in the file. Unix/Linux line endings just use CR. If a crontab is installed without using the crontab -e command, this error might appear.

You can check the line endings by running:
cat -v -e -t /var/spool/cron/username
If you see "^M$" at the end of each line, the file has DOS line endings. Each line should just end with "$".

The fix is to run the dos2unix command on the crontab to correct the line endings:
dos2unix /var/spool/cron/username

 

 

Posted by 김용환 '김용환'

댓글을 달아 주세요