Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

using Net::SSH::Perl and Expect

by jfroebe (Parson)
on Nov 08, 2004 at 22:51 UTC ( [id://406233]=perlquestion: print w/replies, xml ) Need Help??

jfroebe has asked for the wisdom of the Perl Monks concerning the following question:

is it possible to control the SSH->shell via Expect?

I need to connect (using ssh) to a machine and su to another user (I can't ssh to that user - don't ask). Wishing to keep it as perlish as possible, I'm trying not to spawn the ssh command.

if not, no biggie but need a sanity check as it doesn't appear that Net::SSH::Perl and Expect can be used together.

Jason L. Froebe

Team Sybase member

No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Replies are listed 'Best First'.
Re: using Net::SSH::Perl and Expect
by simonm (Vicar) on Nov 09, 2004 at 01:25 UTC
    Yes, Expect works fine with external SSH processes. Here's a snippet from a recent project:
    my $exp = Expect->new; $exp->spawn('sh'); $exp->send( "ssh $host\n" ); $exp->expect(15, 'assword:', '$ ') == 1 or die "Failed at: " . $exp- +>before . " "; $exp->send( $passwd ); ...

      Yup, but what about with Net::SSH::Perl?

      Jason L. Froebe

      Team Sybase member

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: using Net::SSH::Perl and Expect
by teabag (Pilgrim) on Nov 09, 2004 at 11:55 UTC
    You're right,
    Net::SSH::Perl is not to be used with Expect, but you can use Net::SSH though. Net::SSH::Perl has built-in support for the authentication protocols, so there's no longer any hassle of communicating with any external processes.

    from the docs:

    my $ssh = Net::SSH::Perl->new("host1"); $ssh->login("user1", "pass1"); $ssh->cmd("foo"); #I'd say: try su?

    Of course I could be oversimplifying things, I haven't tested it.

    Teabag

    -- Siggy Played Guitar
    Sure there's more than one way, but one just needs one anyway - Teabag
Re: using Net::SSH::Perl and Expect
by Anonymous Monk on Nov 09, 2004 at 06:24 UTC
    Why bother with Expect and Net::SSH::Perl just set up public key authentication and do whatever you want to do from a shell script?

      because there are security measures that must be followed.

      Team Sybase member

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://406233]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found