我正在使用plink
在Windows计算机上的远程服务器(Linux)上运行脚本。脚本的一部分提示输入(对使用不同凭据的其他各种远程服务器进行身份验证)。我不想将密码存储在脚本中,因为每次使用都会出于审核原因而使用各自的密码。
我需要将提示传输到Windows终端窗口,并将输入传输回Linux盒。另外,我需要将所有这些日志写入文件,如下所示:
plink username@unixbox /etc/scrips/myscript.bash > report.txt
report.txt
的提示please enter password for reportBox1?
please enter password for reportBox2?
report.txt
的输出将显示为:please enter password for reportBox1? *
File 1
File 2
File 3
please enter password for reportBox2? *
Data a
data b
data b
plink
更好的东西可以使用,例如腻子的ssh.exe
,请让我知道。
最佳答案
首先,plink
是 PuTTY的ssh.exe
。
如果您希望能够在Windows机器上回答密码提示,则需要告诉plink
使用-t
分配一个伪终端:
plink -t username@unixbox /etc/scrips/myscript.bash
STDOUT
重定向到report.txt
...plink -t username@unixbox /etc/scrips/myscript.bash > report.txt
report.txt
(尽管脚本仍在运行并等待您的输入)。要解决此问题,您需要一些工具,该工具可让您将输出同时重定向到多个目的地-STDOUT
和report.txt
。在* nix世界中,此命令是tee
。 Windows有tee
端口:plink -t username@unixbox /etc/scrips/myscript.bash | tee report.txt
report.txt
中,这可能是一个问题。
https://stackoverflow.com/questions/24533657/