Professional Web Applications Themes

problems using Net::SSH::Perl in a while loop - PERL Modules

Hi Folks I want to usw Net:SSH::Perl to automatically run some commands on several hosts. All the hostnames are stored in a database. I decided to use Net::SSH::Perl because I can configure everything I need. The auth is done by a SSH-Key (RSA). Unfortunately not all of the hosts in the DB have the SSH Key stored in their ~/.ssh/authorized_keys. When I try to connect to one of these hosts using SSH2, my script dies because of a Carp::croak() call in the Net::SSH::Perl::AuthMgr module (line 142). Is there a way to turn off this "die" and just get a error-message ...

  1. #1

    Default problems using Net::SSH::Perl in a while loop

    Hi Folks

    I want to usw Net:SSH::Perl to automatically run some commands on several
    hosts.
    All the hostnames are stored in a database.

    I decided to use Net::SSH::Perl because I can configure everything I need.
    The auth is
    done by a SSH-Key (RSA). Unfortunately not all of the hosts in the DB have
    the SSH
    Key stored in their ~/.ssh/authorized_keys. When I try to connect to one of
    these
    hosts using SSH2, my script dies because of a Carp::croak() call in the
    Net::SSH::Perl::AuthMgr module (line 142).

    Is there a way to turn off this "die" and just get a error-message instead?
    If a hosts doesn't
    have this ssh-key, I don't want to abort my script, I wnat to continue with
    the next hostname
    instead.

    Thanks in advance
    --Thomas


    Thonas Siegenthaler Guest

  2. #2

    Default Re: problems using Net::SSH::Perl in a while loop

    Thonas Siegenthaler wrote:
    > I want to usw Net:SSH::Perl to automatically run some commands on several
    > hosts.
    > All the hostnames are stored in a database.
    >
    > I decided to use Net::SSH::Perl because I can configure everything I need.
    > The auth is
    > done by a SSH-Key (RSA). Unfortunately not all of the hosts in the DB have
    > the SSH
    > Key stored in their ~/.ssh/authorized_keys. When I try to connect to one of
    > these
    > hosts using SSH2, my script dies because of a Carp::croak() call in the
    > Net::SSH::Perl::AuthMgr module (line 142).
    >
    > Is there a way to turn off this "die" and just get a error-message instead?
    > If a hosts doesn't
    > have this ssh-key, I don't want to abort my script, I wnat to continue with
    > the next hostname
    > instead.
    I'm not familiar with this module, but you can normally wrap die calls
    with eval:

    eval {
    print "enter eval\n";
    die "die here";
    print "end eval\n";
    };
    if($){
    print "trapped error - $";
    # handle error
    }
    print "script continues...\n";

    perldoc -f eval

    Mark
    Mark Clements Guest

  3. #3

    Default Re: Re: problems using Net::SSH::Perl in a while loop

    Hi Mark

    thank you for answering. Net::SSH::Perl calls Carp::croak(), which calls
    die().

    The question is what does the module do, if there is no die() call.
    I replaced Carp::croak() with a warn-message. The result is a endless
    list of error messages.

    Has anyone of you ever had a similar problem? Probably I should contact the
    developer of this module. It is not very intelligent to use a die() call
    within a module.
    A good module returns a errorcode and does not cancel the script.

    Greetz
    --Thomas

    Mark Clements schrieb:
    >Thonas Siegenthaler wrote:
    >> I want to usw Net:SSH::Perl to automatically run some commands on several
    >> hosts.
    >> All the hostnames are stored in a database.
    >>
    >> I decided to use Net::SSH::Perl because I can configure everything I
    >> need.
    >> The auth is
    >> done by a SSH-Key (RSA). Unfortunately not all of the hosts in the DB
    >> have
    >> the SSH
    >> Key stored in their ~/.ssh/authorized_keys. When I try to connect to one
    >> of
    >> these
    >> hosts using SSH2, my script dies because of a Carp::croak() call in the
    >> Net::SSH::Perl::AuthMgr module (line 142).
    >>
    >> Is there a way to turn off this "die" and just get a error-message
    >> instead?
    >> If a hosts doesn't
    >> have this ssh-key, I don't want to abort my script, I wnat to continue
    >> with
    >> the next hostname
    >> instead.
    >
    >I'm not familiar with this module, but you can normally wrap die calls
    >with eval:
    >
    >eval {
    >print "enter eval\n";
    >die "die here";
    >print "end eval\n";
    >};
    >if($){
    >print "trapped error - $";
    ># handle error
    >}
    >print "script continues...\n";
    >
    >perldoc -f eval
    >
    >Mark


    Thonas Siegenthaler Guest

  4. #4

    Default Re: Re: problems using Net::SSH::Perl in a while loop


    "Thonas Siegenthaler" <perlthosi.ch> wrote in message
    news:42721058$1_3news.bluewin.ch...
    > Hi Mark
    >
    > thank you for answering. Net::SSH::Perl calls Carp::croak(), which calls
    > die().
    >
    > The question is what does the module do, if there is no die() call.
    > I replaced Carp::croak() with a warn-message. The result is a endless
    > list of error messages.
    >
    You have amended the code in the module. I don't think that's what Mark
    intended. I'll see if I can explain ....

    In your perl script you are calling a Net::SSH::Perl function - and that
    function sometimes dies, killing the whole script. Let's call that function
    Net::SSH::Perl::return_something().

    So - your script contains (in a loop):

    $ret = Net::SSH::Perl::return_something();

    What Mark is suggesting (I think) is that you change your *script* to
    something like:

    eval {$ret = Net::SSH::Perl::return_something();};
    if($) { print "return_something() died with message: $\n"}
    # script keeps running

    There is no need to modify the module.

    (You may be quite correct in saying that these functions ought not to call
    die() .... I'm not arguing about that :-)

    Cheers,
    Rob


    Sisyphus Guest

  5. #5

    Default Re: Re: problems using Net::SSH::Perl in a while loop


    "Thonas Siegenthaler" <perlthosi.ch> píše v diskusním příspěvku
    news:42721058$1_3news.bluewin.ch...
    > Hi Mark
    >
    > thank you for answering. Net::SSH::Perl calls Carp::croak(), which calls
    > die().
    >
    > The question is what does the module do, if there is no die() call.
    > I replaced Carp::croak() with a warn-message. The result is a endless
    > list of error messages.
    >
    > Has anyone of you ever had a similar problem? Probably I should contact
    > the
    > developer of this module. It is not very intelligent to use a die() call
    > within a module.
    > A good module returns a errorcode and does not cancel the script.
    >
    > Greetz
    > --Thomas
    >
    > Mark Clements schrieb:
    >>Thonas Siegenthaler wrote:
    >>> I want to usw Net:SSH::Perl to automatically run some commands on
    >>> several
    >>> hosts.
    >>> All the hostnames are stored in a database.
    >>>
    >>> I decided to use Net::SSH::Perl because I can configure everything I
    >>> need.
    >>> The auth is
    >>> done by a SSH-Key (RSA). Unfortunately not all of the hosts in the DB
    >>> have
    >>> the SSH
    >>> Key stored in their ~/.ssh/authorized_keys. When I try to connect to one
    >>> of
    >>> these
    >>> hosts using SSH2, my script dies because of a Carp::croak() call in the
    >>> Net::SSH::Perl::AuthMgr module (line 142).
    >>>
    >>> Is there a way to turn off this "die" and just get a error-message
    >>> instead?
    >>> If a hosts doesn't
    >>> have this ssh-key, I don't want to abort my script, I wnat to continue
    >>> with
    >>> the next hostname
    >>> instead.
    >>
    >>I'm not familiar with this module, but you can normally wrap die calls
    >>with eval:
    >>
    >>eval {
    >>print "enter eval\n";
    >>die "die here";
    >>print "end eval\n";
    >>};
    >>if($){
    >>print "trapped error - $";
    >># handle error
    >>}
    >>print "script continues...\n";
    >>
    >>perldoc -f eval
    >>
    >>Mark
    I use this module and also tried to cirvent dying of script.
    I manually implemented all machines with the ssh keys and ping them before
    running the relevant part of the script to evade unavailabity of the
    machines.
    Radek H.


    Radomir Hejl Guest

Similar Threads

  1. MacOSX cursor problems in a loop
    By Joshua Davies webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 3
    Last Post: January 16th, 03:40 PM
  2. Read Fix Length Text, Loop Problems
    By William Martell in forum PERL Beginners
    Replies: 0
    Last Post: December 22nd, 04:26 PM
  3. film loop rotation, keycode problems..
    By deepcover webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 3
    Last Post: October 11th, 08:09 AM
  4. libwww-perl Problems
    By Paul Robson in forum PERL Modules
    Replies: 2
    Last Post: September 10th, 02:32 PM
  5. PERL - problems with use
    By Alan Vowles in forum PERL Miscellaneous
    Replies: 1
    Last Post: June 26th, 06:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139