Hello,

I personally still use system /ssh -i $key -h $host/ for perl scripts although using other ways specified (Net::SSH::Perl) might work better for you. I have found that I still like to use system /ssh $blah/ because I am still a fan of pwless SSH keys because of the way I have the security of my network layed out (and I am sure that a lot of people would argue my use of this, but this isn't the time or the place for that).

However, I have found that when I need to have multiple connections or do multiple time intensive things simultaneously that I use Parallel::ForkManager. It just forks off processes and lets you set the max number of processes that you would like to allow to run continuously.

# Begin ForkManager my $_max_procs = 5; $_pm = new Parallel::ForkManager($_max_procs); # Log at process fork $_pm ->run_on_start( sub { my ($pid, $host) = @_; print "Forking process PID: $pid\n"; } ); # Log at process copmletion $_pm ->run_on_finish( sub { my ($pid, $exit_code, $host) = @_; print "Finishing up process PID: $pid\n"; } ); $_pm->run_on_wait( sub { print "Waiting for children to finish.\n" }, 5.0 ); foreach my $ssh_host (keys %{$ssh_host_list}) { # Fork off the children and get going on the queries my $pid = $_pm->start($ssh_host) and next; # do script stuff here # Closing the forked process $_pm->finish; } # Ensure all children have finished $_pm->wait_all_children; exit(1);

In reply to Re: SSH to multiple servers by madbombX
in thread SSH to multiple servers by tobyclemson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.