RTFM Education – Virtualization, VMware, Citrix

Aug 20 2005   2:27AM GMT

Using WinSCP to transfer Scripts

MikeLaverick MikeLaverick Profile: MikeLaverick

Be careful how you use WinSCP to transfer files. If you transferring a script or a text file – be sure to set Text as your option

Failure to do so could potentially corrupt the file. If it’s a script it will return what appear to be syntax errors. This corruption is very easy to spot every end the line will have ^M at the end of it.

If you do copy a file which results in corruption – and its your only copy – this could be deeply annoying. Fortunately, there is a script to correct this if it a happens.

#!/bin/bash
# Du.sh: DOS to UNIX text file converter.

E_WRONGARGS=65

if [ -z “$1″ ]
then
echo “Usage: `basename $0` filename-to-convert”
exit $E_WRONGARGS
fi

NEWFILENAME=$1.unx
CR=’\015′  # Carriage return.

           # 015 is octal ASCII code for CR.
# Lines in a DOS text file end in CR-LF.
# Lines in a UNIX text file end in LF only.

tr -d $CR < $1 > $NEWFILENAME

# Delete CR’s and write to new file.

echo “Original DOS text file is \”$1\”.”
echo “Converted UNIX text file is \”$NEWFILENAME\”.”
exit 0

I saved this as correct.sh

To use:

sh correct.sh problemfile.sh

When you run this script it will report:

Original DOS text file is “problemfile.sh”.
Converted UNIX text file is “problemfile.sh.unx”.

and you annoying ^M will be gone….

I would like to thank Nicke of http://www.alt64.se/vmvbu/ for this script – he didn’t write it – it just seems to be “out there”

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: