Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-28 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found