[英]Run a batch file when Pageant finishes loading SSH keys
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.我编写了两个批处理文件 - 一个用于启动 Pageant 并加载我的密钥,另一个用于将一些文件 ssh 到远程服务器。 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:要启动 Pageant 并加载密钥:
start E:\PuTTY\pageant.exe E:\Keys\priv.ppk
exit
To use pscp:使用 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.
Pageant是GUI应用程序。 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: 因此, Pageant具有
-c
switch ,这使得它在加载密钥后运行指定的程序/批处理文件:
You can arrange for Pageant to start another program once it has initialised itself and loaded any keys specified on its command line.
一旦Pageant初始化了自己的程序并加载了其命令行上指定的任何键,就可以安排Pageant启动另一个程序。 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.
然后,该程序(可能是PuTTY或使用Plink的WinCVS或任何其他工具)将能够使用Pageant加载的键。
You do this by specifying the
-c
option followed by the command, like this:您可以通过在命令后指定
-c
选项来执行此操作,如下所示: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
You can take advantage of the way pageant behaves if another instance is already running.如果另一个实例已经在运行,您可以利用选美的行为方式。 This way you can load a key into pageant and then keep using it in a single script.
通过这种方式,您可以将密钥加载到选美中,然后继续在单个脚本中使用它。
START pageant.exe
TIMEOUT 1
pageant.exe E:\Keys\priv.ppk
:: Do stuff here.
TASKKILL /im pageant.exe
Here's how it works:这是它的工作原理:
START pageant.exe
Start pageant in the background. START pageant.exe
在后台开始选美。TIMEOUT 1
Suspend the script for a second to ensure pageant is running before executing next line. TIMEOUT 1
在执行下一行之前暂停脚本一秒钟以确保选美正在运行。pageant.exe E:\\Keys\\priv.ppk
Launch pageant again and tell it to load the key. pageant.exe E:\\Keys\\priv.ppk
再次启动 pageant 并告诉它加载密钥。 Since another instance of pageant is already running, this instance terminates after loading the key, making the script proceed only then.TASKKILL /im pageant.exe
Kill pageant so the key can no longer be used. TASKKILL /im pageant.exe
杀死选美使密钥无法再使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.