bala_999 has asked for the wisdom of the Perl Monks concerning the following question:
Thanks, Bala#!/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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: echo $? in perl
by Corion (Patriarch) on Nov 30, 2007 at 20:19 UTC | |
by bala_999 (Novice) on Nov 30, 2007 at 20:46 UTC | |
|
Re: echo $? in perl
by roboticus (Chancellor) on Nov 30, 2007 at 20:59 UTC |