Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a tiny script that simply fetches the current date, runs a PHP script and redirect the output (and errors) to a filename containing the current date.

DATE=$(date +"%Y%m%d")
FILE="log/${DATE}.log"
php -q script.php >> $FILE 2>&1

When I run this script on my local machine (Windows 7, Aptana IDE), the PHP script works fine and the logfile has the expected filename, e.g. 20140502.log.

But when I push that script via SFTP to my remote machine and execute that script, the filename looks like this:

20140502?.log?

What might be the problem? Is this an enconding error (e.g. encoding for SFTP uploads is ANSII, where UTF-8 is expected)? Or do I have to change anything in the script itself?

Information about system/shell:

[foo@bar path]$ sh --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)

Funny fact: If that script is called by a cronjob, the question marks don't occur. Only if I manually run the script.

share|improve this question
    
Usually the ? indicates that a character cannot be displayed. Certainly sounds like an encoding difference. Can you give us the output of env|grep -E '(LC|LANG)'? –  0xC0000022L May 2 at 13:23
    
@0xC0000022L Output is LANG=en_US.UTF-8. –  Gottlieb Notschnabel May 2 at 13:32
    
sorry for being unclear. I meant the output on both ends. –  0xC0000022L May 2 at 13:37
    
Sorry for missing that... Unfortunately this command doesn't output anything on Windoze :/ –  Gottlieb Notschnabel May 2 at 13:44
1  
Are you aware that this sequence of redirections (2>&1 >> $FILE) sends stderr to the terminal and stdout to the file? If you want stderr to go to the file as well, you need >> $FILE 2>&1 –  glenn jackman May 2 at 14:34

1 Answer 1

up vote 8 down vote accepted

You probably have some non-printable characters on end of lines (eg. CRLF from Windows), run:

cat -A scriptname

on remote machine, it'll show you all characters in your script. Then, you can convert to unix-like format running

dos2unix scriptname
share|improve this answer
    
Thanks, that was helpful! –  Gottlieb Notschnabel May 2 at 13:33

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.