Re: Net::SSH::Perl bind socket problem



Bonjour

Not many answers, so...

Am Montag, 4. April 2005 21.16 schrieb gui:
> hello,
>
> I'm making a simple script that's supposed to update a certain number of
> boxes, spread around the area.
> my script is supposed to to connect to every hosts (via a file named
> "hosts") using ssh, launch wget to retrieve the patch update, and
> install it.
> Things work fine for the first host of the list. But can never get
> beyong that. I get a "Net::SSH: Can't bind socket to port 1023: Adresse
> déjà utilisée at ./test_ssh.pl line 46" message.
>
> my question is, how can I unbind the socket used by Net::SSH::Perl ?
>
> here's part of my code:
>
> use strict;
> use Net::SSH::Perl;
>
> my ($patchurl,$stout,$sterr,$exit,$ssh);
> my @ids = "$ENV{HOME}/.ssh/id_rsa";
>
> my %params = (
> 'protocol' => 2,
> 'identity_files' => \@ids,
> );
>
> $patchurl = push @ARGV
>
> open HOSTS, "hosts" or die "je n'ai pas réussi à ouvrir le fichier hosts
>
> : $!";
>
> while(<HOSTS>){
>
> (...)
>
> $ssh = Net::SSH::Perl->new($_, %params);
> $ssh->login("root");
> ($stout,$sterr,$exit) = $ssh->cmd("wget -q $patchurl");
>
> (...)
> }
>
>
> thanks

I don't see the exact reason. But after having a look in the code (Perl.pm,
sub _create_socket, which tries ports from 1023 down to 512 to bind to),
maybe the ssh object is not destroyed between the loops. You could try:

** define $ssh as my variable within the loop (not outside as currently)
** put the code within the loop in a separate block, containing the
my-Definition of $ssh
** use "undef $ssh" at the end of the loop (still within it of course)
** Insert some diagnostic code at the beginning of the loop that
a) examines the $ssh object before the second "loop run" and/or
b) sleeps for e.g. a minute, so that you can look whats happening with the
bound port (netstat -neat from cmdline)

I don't have the Modules installed, so I didn't made tests, sorry.

joe
.



Relevant Pages

  • Re: How to get ssh to work in a loop
    ... The for loop scrambles stdin, which upset, ssh/rsh, I get around ths by ... > script for the sun systems which was quite easy as you only need to ... > mounted filesystem by ssh to HP host and then creating a file called ... > doing loads of ssh to each host. ...
    (comp.unix.shell)
  • How to get ssh to work in a loop
    ... I am having a problem getting ssh to work in a "for" loop. ... I am working on is run on a Solaris system and uses a host list to ... script for the sun systems which was quite easy as you only need to ...
    (comp.unix.shell)
  • ssh read from remote host xx.xx.xx.xx:Connection reset by peer
    ... The script does SSH in a loop and every few ... Connection reset by peer ... Here is the ssh command executed in a loop. ...
    (comp.unix.shell)
  • commands from shell script dont work..
    ... Most of the setup is configured(passphrase-less logins via ssh ... but I am unable to get my shell script to work. ... The format of the file "hosts" is: ... debug output. ...
    (comp.unix.shell)
  • Re: ssh known hosts
    ... > Occasionally we ssh to hosts with dynamic ip's using dyndns. ... AFAIK there's no built-in option for it in ssh. ... I'd write a script for it. ... useless inscriptions. ...
    (comp.os.linux.security)