SwaJime has asked for the wisdom of the Perl Monks concerning the following question:

Howdy again,

More info: This is Windows 7 Enterprise running ActivePerl 5.16.3

I've run into another problem.

Whereas before switching to use pageant, this command does not return control to the calling script until the putty window is closed.

putty -ssh -l $user $address -t -m $filename

This command returns immediately and I have no way of knowing when the putty window is closed by the user.

pageant @ppk_files -c putty -ssh -l $user $address -t -m $filename

The reason this is a problem is because I'm trying to run two consecutive calls to putty. One to one server setting up data, the second to a second server to process that data, which is not ready until the user closes the first putty session.

Here are sample files to illustrate: In Test1.pl, the second putty window is not opened until the first putty window is closed. This is the desired behavior. In Test2.pl, the second putty window is opened before the first window is closed. This is not good because the data has not been set up yet.

Test1.pl:

#!/usr/bin/perl # use strict; use warnings; system('putty -ssh -l root 192.168.100.2 -t -m C:\Users\JWSIMP~1\AppDa +ta\Local\Temp\BoKFVjf1B9'); system('putty -ssh -l operations 192.168.10.245 -t -m C:\Users\JWSIMP~ +1\AppData\Local\Temp\d60NPopq6A');

Test2.pl:

#!/usr/bin/perl # use strict; use warnings; system('pageant F:\.keys\acuroot_1_8_12_rsa.ppk F:\.keys\acuroot_1_8_1 +3_rsa.ppk -c putty -ssh -l root 192.168.100.2 -t -m C:\Users\JWSIMP~1 +\AppData\Local\Temp\BoKFVjf1B9'); system('pageant F:\.keys\operations_rsa.ppk -c putty -ssh -l operation +s 192.168.10.245 -t -m C:\Users\JWSIMP~1\AppData\Local\Temp\d60NPopq6 +A');

So, long story short ... how can I get that functionality back? I don't want both sessions opening at the same time.

Please forgive me if this is something that is already documented. I have been searching for an answer for quite some time now.

Thanks,

John

Replies are listed 'Best First'.
Re: How to wait for putty to finish before proceeding.
by Mr. Muskrat (Canon) on Feb 11, 2016 at 17:48 UTC

    It looks to me like pageant is exiting successfully once it has loaded the keys and kicked off the putty command (but before putty has finished. I don't see anything in the docs for pageant to control this behavior. Have you considered something like this? (It looks like all three keys would be loaded for the second putty call anyway.)

    #!/usr/bin/perl use strict; use warnings; system('pageant F:\.keys\acuroot_1_8_12_rsa.ppk F:\.keys\acuroot_1_8_1 +3_rsa.ppk F:\.keys\operations_rsa.ppk'); system('putty -ssh -l root 192.168.100.2 -t -m C:\Users\JWSIMP~1\AppDa +ta\Local\Temp\BoKFVjf1B9'); system('putty -ssh -l operations 192.168.10.245 -t -m C:\Users\JWSIMP~ +1\AppData\Local\Temp\d60NPopq6A');

      I think I got it now, thanks to your post Mr. Muskrat. I found that I had to insert an extra parameter to the system call to tell it not to wait for pageant to finish. Otherwise it was hanging because pageant doesn't exit when run without the -c.

      Thanks bunches :-)

      #!/usr/bin/perl # use strict; use warnings; system(1,'pageant F:\.keys\acuroot_1_8_12_rsa.ppk F:\.keys\acuroot_1_8 +_13_rsa.ppk'); system('putty -ssh -l root 192.168.100.2 -t -m C:\Users\JWSIMP~1\AppDa +ta\Local\Temp\BoKFVjf1B9'); system(1,'pageant F:\.keys\operations_rsa.ppk'); system('putty -ssh -l operations 192.168.10.245 -t -m C:\Users\JWSIMP~ +1\AppData\Local\Temp\d60NPopq6A');

        I don't program much on Windows these days and tend to forget about that trick. Nice.

Re: How to wait for putty to finish before proceeding.
by atcroft (Abbot) on Feb 11, 2016 at 17:48 UTC

    I would probably make the default PuTTY profile try to attempt to use Pageant authentication by default (if memory serves, something like Connection -> SSH -> "Attempt authentication using Pageant" checked; after updating the setting, save as the name "Default Settings"), and launch a single Pageant instance with the appropriate key(s) loaded. I would then expect your Test1.pl script to behave as you intend.

    Hope that helps.

Re: How to wait for putty to finish before proceeding.
by VinsWorldcom (Prior) on Feb 11, 2016 at 17:45 UTC

    Why use pageant then? If you need the key file, why not use the "-i" option of plink.exe? For that matter, why not use plink.exe instead of PuTTY as it does a better job (at least for me) when used in scripts (i.e., not opening a new window)?

      Thanks VinsWorldcom for responding. I'm using pageant because I have multiple possible login keys and I don't want the user prompted for a password. I tried using plink.exe and it does not have sufficient terminal support for the programs that I am running. PuTTY works nicely. I just need to be able to support multiple keys.