Pageant完成加载SSH密钥后运行批处理文件 [英] Run a batch file when Pageant finishes loading SSH keys

查看:124
本文介绍了Pageant完成加载SSH密钥后运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了两个批处理文件-一个用于启动Pageant并加载我的密钥,另一个用于将某些文件ssh到远程服务器上。个别而言,脚本可以完美运行。我正在尝试将它们组合成一个批处理文件,但我无法使其正常工作。



以下是脚本-每个脚本实际上只有一行。 / p>

要启动Pageant并加载密钥:

 开始E:\ PuTTY\pageant.exe E:\键\priv.ppk 

退出

要使用pscp:

  pscp F:\网站\foobar\src\ * foo@178.128 .10.35:/ var / www / html 

问题是第一个脚本启动了密码提示。如果完成此操作,然后启动下一个脚本,则一切正常。但是,我无法将第一个命令的提示完成后再运行第二个命令的方式将这两个脚本合并为一个脚本。我将如何创建执行此操作的批处理文件?

解决方案

您几乎无法在批处理文件中解决此问题。 Pageant是GUI应用程序。几乎无法以某种方式向批处理文件发送信号,表明已完成密钥加载。


因此,选美具有 -c 开关,从而使其运行加载密钥后指定的程序/批处理文件:


一旦Pageant初始化了自己的程序并加载了指定的任何密钥,就可以安排Pageant启动另一个程序。它的命令行。然后,该程序(可能是PuTTY或使用Plink的WinCVS或其他工具)将能够使用Pageant加载的键。


您可以通过指定 -c 选项后跟命令,如下所示:

  C:\PuTTY\pageant。 exe d:\main.ppk -c C:\PuTTY\putty.exe 





所以这应该是您想要的:

 开始E:\PuTTY\pageant.exe E:\Keys\priv.ppk -c C:\path\your_scp_batch.bat 


I've written two batch files - one to launch Pageant and load my keys, and the other to ssh some files onto a remote server. Individually, the scripts work perfectly. I am trying to combine them into a single batch file, but I can't get it to work.

Here are the scripts - only a line each, really.

To launch Pageant and load keys:

start E:\PuTTY\pageant.exe E:\Keys\priv.ppk

exit

To use pscp:

pscp F:\website\foobar\src\* foo@178.128.10.35:/var/www/html

The problem is that the first script launches a password prompt. If I finish this and then launch the next script, everything works perfectly. But I've been unable to combine these two into one script in a way where the second command runs after the prompt from the first one is complete. How would I create a batch file that did so?

解决方案

You can hardly solve this in a batch file. Pageant is GUI application. It can hardly somehow signal back to a batch file that it finished loading keys.

For this reason, Pageant has -c switch, which makes it run a specified program/batch-file after the keys are loaded:

You can arrange for Pageant to start another program once it has initialised itself and loaded any keys specified on its command line. This program (perhaps a PuTTY, or a WinCVS making use of Plink, or whatever) will then be able to use the keys Pageant has loaded.

You do this by specifying the -c option followed by the command, like this:

C:\PuTTY\pageant.exe d:\main.ppk -c C:\PuTTY\putty.exe


So this should to what you want:

start E:\PuTTY\pageant.exe E:\Keys\priv.ppk -c C:\path\your_scp_batch.bat

这篇关于Pageant完成加载SSH密钥后运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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