windows - 从Windows终端远程运行Unix脚本并传回提示

我正在使用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(尽管脚本仍在运行并等待您的输入)。要解决此问题,您需要一些工具,该工具可让您将输出同时重定向到多个目的地-STDOUTreport.txt。在* nix世界中,此命令是tee。 Windows有tee端口:
  • 作为GnuWin32的一部分(这是我正在使用的)
  • 作为UnxUtils
  • 的一部分
  • 作为batch,perl和rexx versions

  • 设置其中之一后,您将执行以下操作:
    plink -t username@unixbox /etc/scrips/myscript.bash | tee report.txt
    

    安全注意事项:如果Linux机器上脚本中的密码提示回显了输入内容,则密码当然也将记录在report.txt中,这可能是一个问题。

    https://stackoverflow.com/questions/24533657/

    相关文章:

    session - 保持 session 状态

    security - Grails 中的真实性 token

    grails - Grails命令对象和输入名称值

    gwt - 使GWT和Grails与Atmosphere插件一起工作

    deployment - 使用Grunt和rsync将远程文件夹与本地文件夹同步

    Perl - 通过包含 require 指令的 SSH 远程运行脚本

    c# - 从C#(WPF)程序向putty.exe实例发送命令

    sockets - 通过Network.Browser进行Socks5连接

    grails - 如何使Grails条件作为左联接执行?

    ssh - GitLab ssh 到本地用户的主机名导致 "fatal: Could not rea