我正在使用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?
相反,我需要它发送密码提示并输入到Linux框,以继续正常运行脚本,但只能远程运行。因此
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
安全注意事项:如果Linux机器上脚本中的密码提示回显了输入内容,则密码当然也将记录在
report.txt
中,这可能是一个问题。
关于windows - 从Windows终端远程运行Unix脚本并传回提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24533657/