开发者

getting the list of the saved session in putty using plink

I am trying to write my scripts under windows to control putty. Say I have a session called mySession. I can send a command to it using:

plink -load mySession -l myUserName -pw myPa开发者_开发技巧ssowrd ps -ef

Now say I have many different sessions saved. is there a way to loop through the list of all my sessions to run this command?

Many thanks


As far as I know, the sessions are stored in the registry (HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions). At least it is the case in my environment here. You could for example use a batch script to access the session names.

@echo OFF
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions"

FOR /F "usebackq" %%A IN (`REG QUERY %KEY_NAME% 2^>nul`) DO (
    FOR /F "tokens=6 delims=\" %%B IN ("%%A") DO (
        @echo ON
        "C:\Program Files\PuTTY\PLINK.EXE" -load %%B -l my_user -pw my_password ps -ef
        @echo OFF
    )
)

I used tokens=6 to only get the last part of the path (%%A). I'm not much fimiliar with batch scripting therefore I don't even know if you need setlocal ENABLEEXTENSION.

If you know your session names you could also simply use the following command:

FOR %%A IN (session1_name session2_name session3_name) DO "C:\Program Files\PuTTY\PLINK.EXE" -load %%A -l my_user -pw my_password ps -ef

Hope this helps, even though your post is nearly one year old. Comments to improve the code are welcome.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜