同时显示和保存Plink输出 [英] Both display and save Plink output

查看:244
本文介绍了同时显示和保存Plink输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用plink.exe登录到远程ssh会话,以使用批处理脚本执行某些任务.对于我来说,在屏幕上的日志文件中获取这些命令的输出也是非常重要的.

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.

我尝试使用通常的批处理方式,即plink servername -m cmd.txt>logfile.log方式,但是问题是它不会在运行批处理脚本的Windows终端上显示它.

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

然后我找到了Plink的-sshlog选项.这样就可以了,即我可以在屏幕上和日志文件中获取输出,但是结果如下:

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

00000f90 56 4c 41 4e 2a 2a 0d 0a 20 65 6e 63 61 70 73 75 VLAN ** .. encapsu 00000fa0 6c 61 74 69 6f 6e 20 64 6f 74 31 51 20 34 30 34关系点1Q 404 00000fb0 0d 0a 20 69 70 20 61 64 64 72 65 73 73 20 31 30 .. ip地址10 00000fc0 2e 37 31 2e 31 39 31 2e 31 34 35 20 32 35 35 2e .71.191.145 255.

00000f90 56 4c 41 4e 2a 2a 0d 0a 20 65 6e 63 61 70 73 75 VLAN**.. encapsu 00000fa0 6c 61 74 69 6f 6e 20 64 6f 74 31 51 20 34 30 34 lation dot1Q 404 00000fb0 0d 0a 20 69 70 20 61 64 64 72 65 73 73 20 31 30 .. ip address 10 00000fc0 2e 37 31 2e 31 39 31 2e 31 34 35 20 32 35 35 2e .71.191.145 255.

我的实际输出开始于以上文本中的"VLAN ** .. encapsu".输出具有这些我不需要的"00000010 74 65 72 ..." bla bla字符.加上主要输出(如果我以交互方式使用Plink时将显示为文字包装",并且看起来很恐怖,这使得普通用户很难理解

My actual output starts at "VLAN**.. encapsu" in the text above The output has these "00000010 74 65 72 ... "bla bla characters which I do not 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

有什么方法可以防止Plink在日志文件中输出不需要的"sshlog"字符?还是在批处理脚本中的Plink/PuTTY会话中还有其他方法可以在屏幕上显示输出并同时记录失败?

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?

我尝试了-sshlog-sshrawlog,但是输出相同.还按照文档尝试了-sessionlog,但是它不起作用!

I tried both -sshlog and -sshrawlog but same output. Also tried -sessionlog as per the documentation but it does not work!

我也尝试过> file.txt,但是它给出了一个空文件!

I tried also > file.txt but it gave an empty file!

预期结果:

encapsulation dot1Q 404 
ip address 10.71.191.145

推荐答案

Plink中没有命令行开关,仅记录可读的输出.

There's no command-line switch in Plink to log only the readable output.

在运行Plink之前,您必须在Windows注册表中配置可打印输出"日志记录.

You would have to configure "Printable output" logging in Windows Registry prior to running Plink.

但是还有其他选择.
请参见显示Windows命令提示符输出并将其重定向到文件.

But there are other options.
See Displaying Windows command prompt output and redirecting it to a file.

因此,这应该可以满足您的需求:

So this should do what you need:

powershell "plink -batch servername -m cmd.txt | tee logfile.log"

这篇关于同时显示和保存Plink输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆