$ssh2->connect($server) or die $!; if ($ssh2->auth_publickey(@auth)) { my $chan = $ssh2->channel(); $chan->blocking(1); $chan->shell(); sleep(2); while(<$chan>) {}; sleep(1); if(!waitforready($chan)) { $chan->close; $ssh2->disconnect(); next SERVER; } print $chan "ps axuf\n"; sleep(5); my %counting = (); my @lines; while(my $line = <$chan>) { push @lines, $line; } } sub waitforready { my $chan = shift; print $chan 'echo "OKCOMPUTER"' . "\n"; my $foundanswer = 0; my $lookedforanswer = 0; while($foundanswer == 0 && $lookedforanswer < 10) { if(my $line = <$chan>) { if($line =~ m/OKCOMPUTER/) { $foundanswer = 1; return 1; } } sleep(1); $lookedforanswer++; } return 0; }