use strict; use Net::SSH2; use Net::SSH2::Channel; my $host = "192.168.xx.xx"; my $user = "appuser"; my $pass = "supersecret"; my $ssh2 = Net::SSH2->new(); #$ssh2->debug(1); $ssh2->connect($host) or die " Cannot connect to $host "; print "Connected to host $host \n"; die "can't authenticate" unless $ssh2->auth(username => $user,password=>$pass ); #,interact=>1); print "Username/password is correct\n"; my $chan2 = $ssh2->channel(); die "Can't create a shell on channel " unless $chan2->shell; die " Cannot set blocking field " unless $chan2->blocking(0); #print $chan2 "1\n"; print $chan2 "hostname \n"; print "Error --> " , $chan2->error() , "\n" ; print "LINE : $_" while <$chan2>; exit; print $chan2 "who \n"; print "LINE : $_" while <$chan2>; $ssh2->disconnect(); #### Output # Connected to host 192.168.xx.xx Username/password is correct Error --> 0