1

I am using Linux 2.6.32-573.26.1

I use a_script to run batch sftp to get file from another Linux server

Here is the way to run a_script

a_script > a_script.log.wri 2>&1

Here is a_script:

echo script start at `date`
sftp -b myCommandFile user@server 
echo script end at `date`

Inside myCommandFile, there are these commands:

lls an_non_exist_file

Because cannot find an_non_exist_file
The error message is:

ls: cannot access an_non_exist_file: No such file or directory  
Shell exited with status 2^M  

So, a_script.log.wri will contain everything, including the line

Shell exited with status 2^M

It is this line to spoil everything.

Because there is a Carriage-return ^M char in the a_script.log.wri , when I attached this file into a email and send to gmail , the gmail cannot open it.

Although it is a file with extension wri , the gamil just does not open it.

I am using Nexus 5x to read the email inside gmail. The Android does not open the attachment file a_script.log.wri

I try to create a file dummy.wri inside Linux with 5 lines and only the 3rd line having a ending carriage-return char. Other 4 lines are ended with LF.

Then, I attach this dummy.wri file in a email and sent to the gmail account.

Well, really it cannot open dummy.wri

If there is no ending carriage-return, everything is fine. I can open it inside the gmail inside Android of Nexus 5x.

So, my question is , how to make sftp NOT to add the carriage-return char when displaying the error message ?

Also, instead of using lls, using ls an_non_exist_file will get similar situation.

Alvin SIU

2
  • Have you tried a_script 2>&1 | sed 's/\r$//' > a_script.log.wri ? – Eugen Rieck Jul 6 '16 at 6:57
  • Yes, I use similar method as a workaround. My question is: since everything is running in unix environment, why the sftp like to use CRLF as line delimiter ? Also, there seems to be no way to tell sftp to use LF as line delimiter. – Alvin SIU Jul 7 '16 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.