Re: [Ssh-sftp-perl-users] bind socket problem
Brought to you by:
dbrobins
|
From: <gd...@te...> - 2005-04-08 13:14:08
|
Robert Landrum wrote:
> > my question is, how can I unbind the socket used by
> > Net::SSH::Perl ?
>
>
> Don't bother... Use fork. When the child process exits, the
> socket will (err... should) unbind. You might have to figure out
> how you're going to handle saving stdout, err, etc. I'd probably
> just write them to a log...
>
I made a stripped version of my script, so that it reflects the
problem. I added your suggestions there, but the problem remain, I
still have a
Net::SSH: Can't bind socket to port 1023: Adresse déjà utilisée at
./test_ssh.pl line 46
message after the second run in the loop
here is the full script :
use strict;
use Net::Ping;
use Net::SSH::Perl;
my ($p,$stout,$sterr,$exit,$cmd);
my (@errping);
open HOSTS, "hosts" or die "je n'ai pas réussi à ouvrir le fichier
hosts!";
$p = Net::Ping->new("icmp");
my @ids = "$ENV{HOME}/.ssh/id_rsa";
my %params = (
'protocol' => 2,
'identity_files' => \@ids,
'port' => 22,
'debug' => 1,
);
while(<HOSTS>){
next if(/^(#|\s+#|\n)/);
chomp;
# ping test
unless ($p->ping($_)) {
print "ip : $_ \nerreur : pas de ping \n\n";
next;
}
#ssh connexion + wget
print "téléchargement du fichier \n";
if (fork){
wait;
}
else{
my $ssh = Net::SSH::Perl->new($_, %params);
$ssh->login("root");
($stout,$sterr,$exit) = $ssh->cmd("wget -q
http://www.google.com ");
}
}
print "mise à jours des ipcops terminé\n";
|