I have a CentOS 6 machine I am trying to run some cronjobs on and the jobs are failing complaining about a carriage return (^M) on the end of the line. Example /var/log/cron entry:

CROND[20344]: (root) CMD (/usr/local/bin/php /usr/local/bin/somescript.php >/dev/null 2>&1^M)
CROND[20213]: (root) CMD (/usr/local/bin/php /usr/local/bin/somescript.php^M)

All this works fine on CentOS 5.x, so looks like it's a CentOS 6 thing. Any suggestions?

link|improve this question
maybe the master control program can help? he was always fond of end-of-lines ? – SpacemanSpiff Sep 8 '11 at 14:05
feedback

3 Answers

Use an editor that uses the correct line organisation. A quick fix is

export EDITOR=vi
crontab -e
:1,$s/^V^M//g
:wq

where ^V^M is Crtl+vCrtl+m

link|improve this answer
feedback

How are you editing the crontab file? Was it copied using any Windows systems, notepad, etc?

These are not UNIX linebreaks. The ^M is a hard carriage return (sometimes known as \r when using escape sequences.) Windows line endings are \r\n (Carriage return, Line Feed) while UNIX line endings are simply \n.

If you used ASCII-mode FTP, or a Windows text editor at any point to get the file contents on the new CentOS system, that's likely the issue.

link|improve this answer
feedback

Install dos2unix and convert it to Unix line ending:

# dos2unix /var/spool/cron/root
link|improve this answer
Don't forget cron's law: You shall not edit the cron file by hand. See Iain's answer how to do it the right way. – mailq Sep 8 '11 at 14:43
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.