0

I'm logging into to a remote ssh session using plink.exe to perform certain tasks using a batch script. Getting the output of these commands in a log file as well on the screen is very important for me.

I tried using usual batch way i.e. "plink servername -m cmd.txt>logfile.log" way but the problem with this is that it wont display it on the windows terminal that the batch script is running on.

Then I found the -sshlog option of plink. This does the work, ie.e I can ge tthe output but on screen and in a log file, but this results in output as follows:

enter image description here

My actual output starts at "te...." in the image above The output has these "00000010 74 65 72 ... "bla bla characters which I donot want. Plus the main output (that would be displayed if i was using plink interactively is "word-wrapped" and looks horrible which makes it very difficult to understand for a general user

Is there any way to prevent plink output unwanted 'sshlog' characters in the log file? or Is there any other way to get the output on screen and log fail simultaneously in a plink/putty session inside a batch script?

Abhi
  • 167
  • 2
  • 16

1 Answers1

0

Consider using tee tool or PowerShell Tee-Object cmdlet or similar.

powershell "plink servername -m cmd.txt | Tee-Object logfile.log"

It will display an output on the screen, but simultaneously store it to a local file.

See also Displaying Windows command prompt output and redirecting it to a file.

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
  • I can not use any external program other than windows terminal. But Thank you I think your answer tells me that I could use windows powershell. PS I'm a total noob – Abhi Nov 17 '17 at 07:43
  • Yes, you can use PowerShell `tee` cmdlet too. See my edited answer. – Martin Prikryl Nov 17 '17 at 08:53