1

I am using Powershell to ssh into my Linux server and tailing my apache log files.

ssh [email protected] -p800 -i ..ssh\id_rsa_test tail /var/log/httpd/access_log -fn0 > test.log

When tailing the text looks fine, When opening the file I piped the text into it looks fine.

The application I am piping the output to fails. When I tail the file I am piping into I see every single character separated by a space.

using out-file with no parameters does the same thing. When I cut and paste the contents of the file in notepad to another notepad file, the other application can read it. How can I fix this?

Here's a sample of what I am referring to:

d o m a i n . c o m 7 2 . 2 2 4 . 2 4 9 . 1 7 - - [ 1 0 / D e c / 2 0 1 3 : 0 7 : 5 0 : 5 6 - 0 6 0 0 ] " G E T / v a n e / v i e w f o r u m . p h p ? f = 1 & s i d = 3 b 4 3 b d 9 9 9 a 7 d b 2 0 c 6 6 9 7 5 b 2 3 8 2 4 a 9 6 1 9 H T T P / 1 . 1 " 2 0 0 9 3 7 6 " h t t p : / / w w w . d o m a i n . c o m / j a n e / v i e w t o p i c . p h p ? f = 1 & t = 8 0 2 3 & p = 3 4 3 4 5 0 & s i d = 3 b 4 3 b d 9 9 9 a 7 d b 2 0 c 6 6 9 7 5 b 2 3 8 2 4 a 9 6 1 9 " " M o z i l l a / 4 . 0 ( c o m p a t i b l e ; M S I E 8 . 0 ;
W i n d o w s N T 6 . 0 ; W O W 6 4 ; T r i d e n t / 4 . 0 ; G T B 7 . 5 ; S L C C 1 ; . N E T C L R 2 . 0 . 5 0 7 2 7 ;
M e d i a C e n t e r P C 5 . 0 ; . N E T C L R 3 . 5 . 2 1 0 2 2 ; . N E T C L R 3 . 5 . 3 0 7 2 9 ; M D D C ; . N E T C L R 3 . 0 . 3 0 7 2 9 ; . N E T 4 . 0 C ; B R I / 1 ; B R I / 2 ) " d o m a i n . c o m 5 . 9 . 1 0 6 . 2 4 1 - - [ 1 0 / D e c / 2 0 1 3 : 0 7 : 5 0 : 5 8 - 0 6 0 0 ] " G E T / r o b o t s . t x t H T T P / 1 . 0 " 2 0 0 - " - " " M o z i l l a / 5 . 0 ( c o m p a t i b l e ; M J 1 2 b o t / v 1 . 4 . 4 ; h t t p : / / w w w . m a j e s t i c 1 2 . c o . u k / b o t . p h p ? + ) "

4
  • Can you show the code where you pipe into powerShell? Commented Dec 10, 2013 at 14:04
  • 1
    Unicode, may I introduce Damiel? That is, Powershell's output is Unicode per default, and what you see are dual byte characters. Commented Dec 10, 2013 at 14:06
  • the command above starting with ssh is within powershell. I open Powershell, then ssh into the Linux server and pipe the output into the third party app or direct it into a file. I am using msysgit for ssh. Commented Dec 10, 2013 at 14:07
  • How are you piping the output? Out-File will format the output as Unicode, but you can set the -Encoding parameter for ASCII. Add-Content and Set-Content will write to the file without doing any re-formatting. Commented Dec 10, 2013 at 14:25

1 Answer 1

2

If you pipe our output though out-file, set-conent, or add-content you can use the -Encoding parameter to force it to ASCII:

ssh [email protected] -p800 -i ..ssh\id_rsa_test tail /var/log/httpd/access_log -fn0 | Add-Content  test.log -encoding ASCII

ssh [email protected] -p800 -i ..ssh\id_rsa_test tail /var/log/httpd/access_log -fn0 | Set-Content  test.log -encoding ASCII

ssh [email protected] -p800 -i ..ssh\id_rsa_test tail /var/log/httpd/access_log -fn0 | Out-File  test.log -encoding ASCII
Sign up to request clarification or add additional context in comments.

7 Comments

This works for saving to the file and is also wonderful. I used out-file -encoding ASCII for that. But I still need to pipe the output to another app in real time. How can I change from unicode to ASCII in a pipe?
Try: app1 | out-string | app2
Tried that last night, but out-file demands to save to a file.
Not out-file, out-string.
What it's doing now is just hanging as though SSH never releases control to the next app.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.