1

Coming from Why is my crontab not working, and how can I troubleshoot it? i still don`t know why my command is not executed.

I got same command for root and www-data

enter image description here

and my cron logs shows that cron is executed every minute

enter image description here

however, i never got /tmp/crontest.log file. I notice this problem because i wanted to make wordpress external cron (executing php file).

Of course, executing that command from command line is working.

Any tips?

4
  • /usr/bin/env is being used to run any given script with preloaded environment variables. The crontab is weird, what do intent to echo to the temp file?
    – Anatoly
    Jul 12, 2015 at 19:05
  • what are the permissions on /tmp? They should be 1777 - rwxrwxrwt. Jul 12, 2015 at 19:35
  • 1
    I also see a ^M after your cron line - ... CMD /usr/bin/env &> /tmp/crontest.log^M) Jul 12, 2015 at 19:36
  • @toppledwagon ofc 1777. About ^M, check accepted answer. Jul 12, 2015 at 23:23

2 Answers 2

3

Your crontab file has the wrong lineendings - it's got carriage return (CR)/linefeed (LF) endings. You can see this in your first screenshot, where there's a [dos] after the filename. Unix systems expect lines to be terminated by linefeeds only, whereas Windows systems use a carriage return/linefeed pair.

There are a few ways to correct this. As you seem to be familiar with vi, I'd suggest this to replace the CR/LFs with LFs. Just edit your crontab and then do the search and replace.

2
  • perfect answer. I`m using c#/windows to communicate with linux via ssh and i know that there is difference between windows and linux new line, but i edited cron import file with webmin, deleted the new line, reenter and save with webmin, but looks like webmin know it is dos file and save new line in dos style? Jul 12, 2015 at 23:21
  • If the used editor is vi or vim, do :set notextmode followed by :wq to change all CR-LF to LF only.
    – ott--
    Jan 10, 2016 at 7:11
1
  1. The dos2unix command can convert DOS CR/LF characters in your files to proper LFs. Probably easier than messing around in an editor.
  2. Depending on your editor, it may not leave a trailing LF at the last line either. Some cron implementations still fail to run the last command in a crontab file unless terminated with an LF character at the end.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .