Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I write the following VB script in order to run commands from WIN XP on Linux machine and redirect the output command to out.txt file ( under C:\ )

My VB script I print the /etc/hosts file from Linux machine in to out.txt file

Script works fine but I have one problem:

/etc/hosts file was printed in out.txt file with one long line , in place of three lines

Example: (out.txt)

         127.0.0.1      localhost  19.20.183.99  MY_IP 10.10.10.10 LOOP

In place to print the following host file in out.txt

127.0.0.1      localhost
19.20.183.99  MY_IP
10.10.10.10 LOOP

MY VB script

Const TARGET_HOST = "19.20.183.99"
const PATH =  "cat /etc/hosts" 
const LOGIN = "root"
const PASS = " dgdgd "
Const PLINKPATH="""C:\dir1\plink.exe"""
Set Sh = CreateObject("WScript.Shell")

CMD = " echo y | " &   PLINKPATH  & " -ssh -pw " & PASS & LOGIN & "@" & TARGET_HOST & " " & PATH 

Sh.Run "cmd /k" & CMD &  " > ""C:\out.txt""" , 1, True

Please advice what I need to fix in my VB script in order to print the correct hosts file ( line by line ) and not as one long line ?

share|improve this question
    
you really should troubleshoot things then you'd see that a file with a letter and a new line in linux, is smaller than a file with a latter and a new line in windows. In fact if in windows you do echo a>file1 then you see the file is 3 bytes, and you could ask the question -why-. And find out why. Windows using CRLF is extremely well known. if you ever read up about carriage return you'd probably learn windows uses it and linux just uses LF. i'd think one should run into that fact dozens of times. –  barlop Sep 1 '13 at 21:52

1 Answer 1

up vote 0 down vote accepted

Linux systems use Line Feed for line breaks, whereas windows uses Carriage Return + Line Feed. http://en.wikipedia.org/wiki/Newline

In your case, I would run PATH through sed, to replace the LF's with CRLF's

Const PATH = cat /etc/hosts | sed -e 's/$/\r/' 

http://en.wikipedia.org/wiki/Unix2dos

share|improve this answer
    
I haven't read his whole question, and it's shocking that a person(the questioner apparently) could know vbscript and where the hosts file is in linux, and not know about CRLF in windows and LF in linux. but anyhow, you write "replace the LF's with CRLF's" Then you write 's/$/\r/' what use would that replacement be - you're saying put CR at the end. that isn't used by any OS. it's either \r\n(CRLF) or it's \n(LF). never just \r(CR). and your sed replacement just puts a CR there. –  barlop Sep 1 '13 at 21:46

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.