Net::SSH::Perl : multiple connections fails

Discussion in 'Perl Misc' started by Helge Cramer, Oct 10, 2003.

  1. Helge Cramer

    Helge Cramer Guest

    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
     
    Helge Cramer, Oct 10, 2003
    #1
    1. Advertising

  2. Helge Cramer

    lostriver Guest

    On 10 Oct 2003 09:04:23 -0700, Helge Cramer wrote:
    > 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?


    --
    ..signature: No such file or directory
     
    lostriver, Oct 10, 2003
    #2
    1. Advertising

  3. Helge Cramer

    Helge Cramer Guest

    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
     
    Helge Cramer, Oct 13, 2003
    #3
  4. Helge Cramer

    ko Guest

    Helge Cramer wrote:
    > 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
     
    ko, Oct 14, 2003
    #4
  5. Helge Cramer

    lostriver Guest

    On 13 Oct 2003 05:35:43 -0700, Helge Cramer wrote:
    > 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";
    }




    --
    ..signature: No such file or directory
     
    lostriver, Oct 14, 2003
    #5
  6. Helge Cramer

    Helge Cramer Guest

    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
     
    Helge Cramer, Oct 15, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jobs
    Replies:
    2
    Views:
    917
  2. Tench Johnson
    Replies:
    1
    Views:
    330
    Biff Tannen
    Apr 23, 2010
  3. salamond

    net/ssh in ruby. ssh.exec fails

    salamond, Feb 17, 2011, in forum: Ruby
    Replies:
    0
    Views:
    278
    salamond
    Feb 17, 2011
  4. Ishmael

    Net::SSH::Perl make test fails

    Ishmael, Jan 11, 2007, in forum: Perl Misc
    Replies:
    1
    Views:
    166
    Ishmael
    Jan 17, 2007
  5. Replies:
    0
    Views:
    134
Loading...

Share This Page