Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following cron job:

 */5 8-20 * * * php /var/www/user/cron_email.php >> /var/www/log/log.txt

It creates the following file:

david@ubuntu:/var/www/log$ ls -l
-rw-r--r-- 1 root root   540 2011-05-30 17:10 log.txt?

Why is it creating a trailing question mark? How can I stop that?

(I am logging in on the console and seeing the results with no editor so I know that "?" is there.)

And this is the only file that has a trailing '?' so I know its not an editor problem. I am not even using any editor, Im just viewing the console CRT screen.

share|improve this question
    
How did you add the job to the crontab? –  Xint0 May 30 '11 at 21:51

3 Answers 3

up vote 3 down vote accepted

Running this command will provide more info:

$ crontab -l | cat -tve

I'm fairly confident you will see extra characters at the end of the output, something like this:

*/5 8-20 * * * php /var/www/user/cron_email.php >> /var/www/log/log.txtM-U$

the dollar sign just signals end of line (-e option to cat). Anything betwee .txt and $ is extra garbage, probably due to reasons listed in other answers.

The easiest way to fix this is to set your $EDITOR to a simple editor and re-edit the crontab. For example:

$ EDITOR=/usr/bin/pico crontab -e

then remove any extraneous characters at the end of the line.

share|improve this answer
    
That fixed it, thanks –  davidjhp May 31 '11 at 0:03

Your editor is using CRLF as EOL instead of just LF, and that character is being considered part of the filename. Make sure your editor uses the correct line endings.

share|improve this answer
    
I dont think so, I logged in on the console and I can see that question mark there. –  davidjhp May 30 '11 at 21:29
    
ls -q will show unprintable characters in a filename as ?. Are you sure it isn't aliased? –  Ignacio Vazquez-Abrams May 30 '11 at 21:32
    
And this is the only file that has a trailing '?' so I know its not an editor problem. I am not even using any editor, Im just viewing the console CRT screen. –  davidjhp May 30 '11 at 21:32

The man page of ls shows that if the command is run inside a terminal, control characters will be displayed as a '?' character instead of the actual control character. In this case, the control character will presumably be an errant line-feed left by your editor instead of the standard UNIX \n character.

You need to configure your text editor to use UNIX line-endings (LF), and not use CRLF, or use the 'visudo' command-line editor to alter your cronjobs which will handle this for you automatically.

share|improve this answer
    
I am not using any editor! –  davidjhp May 30 '11 at 21:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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