I am trying to use the Net::SSH::Perl module ( that one being the pure perl module, as opposed to Net::SSH which is a wrapper around system() calls ) and running an 'su' on a remote box. It isn't working.

Specifically, I cannot seem to get the Net::SSH::Perl->cmd method to respond to the password: prompt. It appears the remote 'su' is timing out while waiting for input.

Has anybody else done this? If so, how? I have looked at installing my own handler, but thought to see how somebody else has done this before I hurt myself figuring it out.

Any help I could get from my fellow monks would be most appreciated.

For what it is worth, my code looks like:

#!/usr/local/bin/perl -w use strict; use Net::SSH::Perl; use Data::Dumper; # I set the use_pty because that was the only way I could # get this to work using /usr/local/bin/ssh. It is really # only a guess. my $ssh = Net::SSH::Perl->new( "172.20.28.48", debug => 1, protocol => + 2, use_pty => 1 ); $ssh->login(); my ($out, $err, $exit ) = $ssh->cmd('su - root -c "touch /var/tmp/sill +y3"', '*******'); print "out = $out\nerr = $err\nexit = $exit\n";
and the (slightly truncated) debug output looks like this:
borris: Login completed, opening dummy shell channel. borris: channel 0: new [client-session] borris: Requesting channel_open for channel 0. borris: channel 0: open confirm rwindow 0 rmax 32768 borris: Got channel open confirmation, requesting shell. borris: Requesting service shell on channel 0. borris: channel 1: new [client-session] borris: Requesting channel_open for channel 1. borris: Entering interactive session. borris: Sending command: su - root -c "touch /var/tmp/silly3" borris: Requesting service exec on channel 1. borris: channel 1: send eof borris: channel 1: open confirm rwindow 131065 rmax 32768 borris: input_channel_request: rtype exit-status reply 0 borris: channel 1: rcvd eof borris: channel 1: output open -> drain borris: channel 1: rcvd close borris: channel 1: obuf empty borris: channel 1: output drain -> closed borris: channel 1: close_write borris: channel 1: send close borris: channel 1: full closed Use of uninitialized value in concatenation (.) or string at su.pl lin +e 12. out = err = su: Sorry exit = 1

mik
mikfire


In reply to Net::SSH::Perl and su by mikfire

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.