#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; sub link_ssh { my $ssh = shift; $ssh->error and die "Couldn't establish SSH connection: " . $ssh->error . "\n"; my @lines = $ssh->capture(qq{ps}); print @lines; } sub main { my $host = "morya:morya\@10.137.73.214"; my $ssh = Net::OpenSSH->new( $host ); my @childs = (); # most hosts use MaxSessions=10 as default for ( 1 .. 12 ) { my $kid = 1; $kid = fork; push( @childs, $kid ) if ($kid); if ( !$kid ) { # child process eval { link_ssh $ssh, $_; }; if ($@) { print "child $_ ERR $@\n"; } exit; } } print "main $$ waiting childs\n"; waitpid( $_, 0 ) foreach @childs; return 0; } exit(main);