net::ssh::perl error handling

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default net::ssh::perl error handling

    Hi

    im working on a script that uses Net::SSH::Perl
    The problem is that i dont know how to handle errors properly.
    When the script tries to connect to a host that has no sshd running or
    is completly down
    then the script exits with a error like:

    Can't connect to x.x.x.x, port 22: Connection timed out at
    /usr/lib/perl5/site_perl/5.8.0/Net/SSH/Perl.pm line 206.

    but it would be much nicer if the error would be stored in a var and
    the script continues.
    Or at least it should die with a proper message.
    i tried something like:

    $ssh = Net::SSH::Perl->new($host) || die "error connecting to $host";

    but had no success :/

    any help is welcome

    twix

    --
    [url]http://www.tuxhilfe.de.vu[/url]
    NightTwix Guest

  2. Similar Questions and Discussions

    1. Error handling
      In you provide labels or line numbers in your code, you can use ERL to get the most recent label/line number. Using line numbers does slow down...
    2. CF Error Handling
      I currently have no error handling with the website I am working with. I want to start integrating it in. The error I am most concerned about is...
    3. better error handling
      Stijn Goris wrote: if you print out the contents of $uploaddir.$_FILES you'll find that it's not what you expected, I think.
    4. Error handling and custom error messages
      How can I get more informations about last error? I get the last error number with @@ERROR, but I don't know what is the source of error. For...
    5. Error handling in SQL
      Hi. I came across following stored procedure. CREATE PROCEDURE . @iId int, @iErrorCode int OUTPUT AS
  3. #2

    Default Re: net::ssh::perl error handling

    [email]freestyler@6pack.de[/email] (NightTwix) wrote in message news:<4ec94413.0311301607.1af88fc4@posting.google. com>...
    > Hi
    >
    > im working on a script that uses Net::SSH::Perl
    > The problem is that i dont know how to handle errors properly.
    > When the script tries to connect to a host that has no sshd running or
    > is completly down
    > then the script exits with a error like:
    >
    > Can't connect to x.x.x.x, port 22: Connection timed out at
    > /usr/lib/perl5/site_perl/5.8.0/Net/SSH/Perl.pm line 206.
    >
    > but it would be much nicer if the error would be stored in a var and
    > the script continues.
    > Or at least it should die with a proper message.
    > i tried something like:
    >
    > $ssh = Net::SSH::Perl->new($host) || die "error connecting to $host";
    >
    > but had no success :/
    >
    > any help is welcome
    >
    > twix
    I don't know the module exactly but it's generally a good idea not to
    die if you don't want to :-) Try this:

    --- SNIP ---
    $ssh = Net::SSH::Perl->new($host);
    if( ! $ssh )
    {
    do_some_error_handling...
    }
    --- SNIP ---

    If this does not work (i.e. the Net::SSH::Perl raises an exception you
    should catch it using eval:

    --- SNIP ---
    eval "$ssh = Net::SSH::Perl->new($host);";
    if( $@ )
    {
    do_some_error_handling...
    }
    --- SNIP ---

    Helge
    HEKR Guest

  4. #3

    Default Re: net::ssh::perl error handling

    /usr/lib/perl5/site_perl/5.8.0/Net/SSH/Perl.pm line 206.

    Can't tell how old this thread is but the problem is that there is a die in the module itself as seen in the error message. I'm still pretty much a beginner but the two solutions presented didn't work. I've resulted to using ping to verify that I can reach whatever it is I'm connecting to before passing the IP to net::SSH:perl. Cumbersome but it prevents the crash.
    Keegan Holley is offline Junior Member
    Join Date
    Aug 2011
    Posts
    1

Posting Permissions

  • You may not post new threads
  • You may 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