Net::SSH::Perl : multiple connections fails

H

Helge Cramer

I installed Net::SSH::perl and everything works fine ;-)
But trying to connect to multiple servers brings out error-message:

Net::SSH: Can't bind socket to port 1023

$ssh1 = Net::SSH::perl->new('host1', protocol => '2,1');
$ssh2 = Net::SSH::perl->new('host2', protocol => '2,1');

Alternatively, I tried to set up the second connection after remote
commands on first connection exited, but it just brought up the same
error.
I think, I am missing a hint for "unbinding" the socket/close the
connection before connect to second server or a hint for an
opportunity to speak with both servers at the same time.

I am running RedHat9 on an intel-box and on remote servers sshd is
listening to port 23 only.

Thanks for any hint/solution,

Helge Cramer
 
L

lostriver

I installed Net::SSH::perl and everything works fine ;-)
But trying to connect to multiple servers brings out error-message:

Net::SSH: Can't bind socket to port 1023

You are not runing it as root, right? Only root can use local ports 0-1023....
Are you sure you do not have 'privileged => 1' set?
 
H

Helge Cramer

Yes, I do run the script as root, so Net::SSH::perl should set
privileged=1 on its own (as described in the documentation).
Any further suggestions (perhaps how to make connection 2 after
connection 1)?

Helge Cramer
 
K

ko

Helge said:
Yes, I do run the script as root, so Net::SSH::perl should set
privileged=1 on its own (as described in the documentation).
Any further suggestions (perhaps how to make connection 2 after
connection 1)?

Helge Cramer

Have you tried the sock() method? From the Net::SSH::perl docs:

$ssh->sock

Returns the socket connection to sshd. If your client is not connected,
dies.

Then use the return value to explicitly shutdown/close the connection,
and make try making a second connection.

Off-topic, but have you thought about using a combination public key
authentication and cron setup? Not sure exactly what you want to do, but
this method will also allow you to control what gets executed (since
you're running root). Just a suggestion, though...

HTH - keith
 
L

lostriver

Yes, I do run the script as root, so Net::SSH::perl should set
privileged=1 on its own (as described in the documentation).
Any further suggestions (perhaps how to make connection 2 after
connection 1)?

Post your code. It is hard to guess what you are doing...

This work just fine for me:


use Net::SSH::perl;

foreach (1..3) {
$i = Net::SSH::perl->new(localhost);
$i->login('username', 'password');
push @connections, $i;

next unless $_ == 2;
my ($stdout, $stderr, $exit) = $i->cmd('ls');
print "First loop: $_: $stdout\n";
}


foreach $i (@connections) {
my ($stdout, $stderr, $exit) = $i->cmd('ls');
print "Second loop: $stdout\n";
}
 
H

Helge Cramer

I tried the code You posted, but it is not working for me either. I am
still getting error message:

Net::SSH: Can't bind socket to port 1023: Die Adresse wird bereits
verwendet

(Address already in use)


Here my modified code according to Your last posting:

my %servers = (
host1 => {
host => "host1.somewhere.net",
user => "user1",
pass => "pass1",
logdir => "www/logs",
cmd_zip => "gzip -9 www/logs/*_access",
cmd_ls => "ls www/logs/*_access.gz",
cmd_delete => "rm -f www/logs/*.gz",
hold_flag => 0,
},
host2 => {
host => "host2.somewhere.net",
user => "user2",
pass => "pass2",
logdir => "www/logs",
cmd_zip => "gzip -9 www/logs/access_log_*",
cmd_ls => "ls www/logs/access_log_*.gz",
cmd_delete => "rm -f www/logs/*.gz",
hold_flag => 0,
},
);

my @connections;
my $i;
my $server;
foreach $server (keys %servers) {
$i = Net::SSH::perl->new($servers{$server}{host});
$i->login($servers{$server}{username});
push @connections, $i;

next unless $_ eq "host2";
my ($stdout, $stderr, $exit) = $i->cmd('ls');
print "First loop: $_: $stdout\n";
}


foreach $i (@connections) {
my ($stdout, $stderr, $exit) = $i->cmd('ls');
print "Second loop: $stdout\n";
}


According to the suggestion to cron: Yes, I want a cron-job to do the
thing, but there a several servers I want to connect to and so I want
just running the cron-job on one system in my office. Authentification
is through public-key (rsa) as servers do support it.
Password-Authentification is only for remote servers where I do not
have root-access and no opportunity to authentificate via key-pairs.

Helge Cramer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top