#!/usr/local/bin/perl use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => "$host", user => 'xxxx', timeout=>7, raw_pty => 1 ); $password="yyyyy"; Login in to the host ------------------------- $prompt="[Pp]assword"; $ssh->run_ssh(); #Added newly $ssh->waitfor('qr/\(yes\/no\)\?$/',2); $ssh->send("yes\n"); $ssh->waitfor('qr/$prompt:\s*$/',5); $ssh->send("$password"); Executing commands on host -------------------------------- $cmd="ls"; my $output=$ssh->exec($cmd,"5") or die "Error\n"; eval { $mov=$ssh->exec("echo $?\n","2"); }; warn $@ if $@; print "value is $mov\n"; BY default this value is 0,even if we execute the invalid commands. $ssh->close();