Run a batch file when Pageant finishes loading SSH keys

隐身守侯 提交于 2019-12-22 18:19:31

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/52472628/run-a-batch-file-when-pageant-finishes-loading-ssh-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!