Hi,
I have a strange problem. When I run this in the debugger, I see a successful su to the passed user. But when I run this without the debugger, I get the message "Authentication Failed".

I used Net::SSH::Expect for the $ssh.

This is my code to connect and do a su user.

sub su_login { my ($self, $user, $pass) = @_; my $ssh = $self->ssh(); my $log = $self->log(); my $cmd = ''; if($user eq 'root') { $cmd = 'su -'; } else { $cmd = "su $user"; } $ssh->send($cmd); $ssh->waitfor('Password:\s*\z', 3) or return (undef, "Cannot su a +s $user"); $ssh->send($pass); my $output = $ssh->exec('whoami'); $log->message($output); if ($output =~ /sorry|failure/i ) { $log->error("Cannot su as $user"); return (undef, "Failed to login as $user"); } else { $log->message("Successfully logged in as $user"); } return ($ssh, "su $user successful"); }

In reply to Script works in debugger, but fails when run (using Net::SSH::Expect) by rajadurai

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.