HI , I am running a perl script which will login and execute the commands on the host.After executing each command i want to find out whether the command execute is sucess or not..I am not able to find it! Below is the code..
#!/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();
Thanks, Bala

In reply to echo $? in perl by bala_999

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.