Respected Monks,

It made my task easier and fekt happy when I came to know about the new Net::SSH2 perl module.

I have implemented this modules into my CGI application which connects to remote system and performs some execution of commands or else editing and saving of files.

I have initially tested the module with a sample perl script and could capture all the errors which could be generated during the process.

Here is the part of the code where we are trying to connect. Where ip -> is the remote systems IP

my $ssh2 = Net::SSH2->new; die "can't connect" unless $ssh2->connect("ip");
For eq: When SSH service is down on the remote system the error occured is

Net::SSH2::connect: failed to connect to <ip>:22: Connection refused a +t test.pl at line 10

I felt the error can be captured and have used the same in my CGI application and when ever the SSH service is down for a remote system. I am not able to capture the error, but it is being obtained in the

/var/apache/logs/error_log file

Net::SSH2::connect: failed to connect to ip:22: Connection refused at +./scripts/ssh_subrtns.pl line 2644

Here is the part of the code where I am trying to connect in my CGI application.

my $ssh2 = Net::SSH2->new(); #return "Can not connect $rip " unless ($ssh2->connect($rip)); + ## or die "Can not Connect $rip "; if ( ! ($ssh2->connect($rip)) ) or die "Can not Connect $rip " +; { print qq{<font color="red"><b> Can't Connect to $rip +</b></font></body></html>} ; exit; }
I have used "return" but did not find any luck and tried out die also but unable to print this error on the CGI interface. I need to display this error message for more readability to the user.

Please help me out if I am doing any thing wrong over here. Need your suggestions if any

Thanks in advance.


Sushil Kumar

In reply to Net::SSH2 Connect - Does not return error by msk_0984

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.