#!/usr/bin/perl use strict; use warnings; use Net::SSH2; use File::Remote; my $user = ''; my $pass =""; #my $cmd = "ls"; my %host; $host{'portaltest'} = ""; $host{'opatest'} = ""; eval{ foreach my $key (keys(%host)){ my $ssh = Net::SSH2->new(); $ssh->connect($host{$key}); $ssh->auth_password($user, $pass) or die "not able to login\n"; print "password authenticated\n" if ($ssh->auth_ok()); my $chan = $ssh->channel(); $chan->blocking(0); $chan->shell(); $chan->write("ls"); print "ls command executed\n"; select(undef,undef,undef,0.2); my $buf; print $buf while defined (my $len = $chan->read($buf,512)); # print "ls printing\n"; $chan->close(); } }; warn $@ if $@;