Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Net::SSH::Perl and SSH protocols

by radiantmatrix (Parson)
on Mar 24, 2008 at 14:56 UTC ( [id://675910]=note: print w/replies, xml ) Need Help??


in reply to Net::SSH::Perl and SSH protocols

If you just need to connect and run a script, consider using the command-line SSH via the Expect module. I've found that quite helpful. Something like:

use strict; use warnings; use Expect; my $login = "xxx"; my $pass = "xxx2"; my $test_dir = "/foo/bar/"; my $cmd = "if [ -d $test_dir ]; then echo DIR_EXIST:1; else echo DIR_E +XIST:0; fi"; my $timeout = 30; my $ex = Expect->new('ssh','-t',"$login\@hostname",$cmd); # the -t fo +rces TTY allocation, helpful for Expect! $ex->expect( $timeout, [ qr/password:\s*$/i => sub { $ex->send($pass,"\n"); return 1; } ] +, [ timeout => sub { warn "Timeout waiting for password prompt"; ret +urn 1; } ], ); $ex->expect ( $timeout, [ qr/DIR_EXIST:\d/ => sub { print "Result: ",$ex->match(); } ], );

I've used this approach to do remote password-resets, user deletes, software installation, &c. It's a bit more code, but you get a lot more control.

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 21:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found