Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Net::OpenSSH across fork & exec

by dwalin (Monk)
on Mar 15, 2011 at 15:33 UTC ( #893356=perlquestion: print w/replies, xml ) Need Help??

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

Hello wise brethren, calling for your aid again. The question is simple this time: is there a way to pass Net::OpenSSH master connection socket to exec()'d process? Something like this:
#!perl -w use Net::OpenSSH; my $ssh = Net::OpenSSH->new("hostname"); if (my $pid = fork) { # wait for children, do something } elsif ($pid == 0) { exec "another_perl_script"; } __END__ another_perl_script: #!perl -w use Net::OpenSSH; # do something to retrieve master connection my $ssh = Net::OpenSSH->... $ssh->system("remote command"); ...

Perhaps I wasn't attentive enough but I can't find a way to pass master socket to new(). I can pass it the same control directory but that results in Net::SSH creating another master connection.

Thanks in advance!

Regards,
Alex.

Replies are listed 'Best First'.
Re: Net::OpenSSH across fork & exec
by salva (Abbot) on Mar 15, 2011 at 16:56 UTC
    I have added the feature to reuse an external OpenSSH master connection to the latest development version (1.51_05):
    my $ssh = Net::OpenSSH->new($host, reuse_master => 1, ctl_path => $from_first_script);

    Though, I don't really like calling the new option "reuse_master", I am thinking of changing it to "external_master".

      Thanks for such quick reply. I have removed my previous suggestion, since it appears that you have already did that. :)

      Regards,
      Alex.

        yes, now, it works as follows:
        #!perl -w use Net::OpenSSH; my $ssh = Net::OpenSSH->new("hostname"); if (my $pid = fork) { # wait for children, do something } elsif ($pid == 0) { exec "another_perl_script", $ssh->get_ctl_path; } __END__ another_perl_script: #!perl -w use Net::OpenSSH; my $ssh = Net::OpenSSH->new($host_or_some_dummy_value, ctl_path => $ARGV[0], reuse_master => 1); $ssh->system("remote command");
      FOSS for the win!
      salva++

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://893356]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2020-10-23 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (234 votes). Check out past polls.

    Notices?