Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Net::SSH::Perl won't set SSH options?
Hi folks,
 
I have a test script that remotely runs a command via SSH. The problem
is that I get prompted to accept a host key if it's missing from my
known_hosts file.
The ssh option StrictHostKeyChecking if set to 'no' is supposed to
accept a missing host key. I've tested this and it works from a command
line, but 
I can't get the following code to do the same. (I don't think the
ConnectTimeout works correctly either, FYI).
 
Can anyone see what I'm doing wrong?
 
Thanks!
 
richf
 
#!/usr/local/bin/perl 
use warnings;
use strict;
use Net::SSH::Perl;
 
my %config = (
server              => 'server',
passwords       => [qw(foo bar)],
command        => 'who',
user                => 'root',
);
 
my $output = collect_data_over_ssh(\%config);
print "\n\n", @$output, "\n\n";
 
sub collect_data_over_ssh {
my $config = shift;
 
my $server              = $config->{server};
my $passwords   = $config->{passwords};         # array ref
my $command             = $config->{command};
my $user                = $config->{user};
 
my @output;
my $stdout;
my $stderr;
my $exit;
 
my %options = (
debug => 1,
options => [
"ConnectTimeout 3",
"StrictHostKeyChecking no",
],
);
 
 
PASSWD:
for my $pass (@$passwords) {
 
my $ssh = Net::SSH::Perl->new($server, %options) or warn
"Can't connect via SSH $!\n";
 
eval {
$ssh->login($user, $pass);
};
next PASSWD if ($@);
 
($stdout, $stderr, $exit) = $ssh->cmd($command);
 
if ($stdout) {
@output = $stdout;
}
else {
@output = $stderr;
}
last PASSWD;
}
return \@output;
}



Report this thread to moderator Post Follow-up to this message
Old Post
Richard Fernandez
04-03-08 12:19 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 11:07 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.