• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 149
  • Last Modified:

how do I email notification if telnet session fails to open

How can I call an email subroutine if a telnet session fails to open (device may be out of service)?

I use this syntax to open a telnet session, but need to be notified if it fails via email.

$telnet->open($IP);
0
lormand
Asked:
lormand
  • 3
  • 3
1 Solution
 
wilcoxonCommented:
Which module are you using to handle the telnet?

I would guess you could do this:

$telnet->open($IP) or &mail_me;

Then define sub mail_me to be whatever you want.

I can't verify that the above will work without knowing what module/code you are using for Telnet.
0
 
lormandAuthor Commented:
Thanks for the response.  I'll include the modules I use in future queries.

I am using Net::Telnet.

I tried the above "$telnet->open($IP) or &mail_me" prior to this query and it did not work.

I get a "pattern match timed-out"
0
 
wilcoxonCommented:
It looks like what you need to do is this (from perldoc Net::FTP)...

$telnet->errmode(\&mail_me);

Put the above before your call to $telnet->open.  If you want to restore the default handling after calling open, then call $telnet->errmode('die').
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
lormandAuthor Commented:
This works great!  Much appreciated.  I have a better understanding of Errmode now.

I tried it without the \ before the &mail_me.  I am developing on a win32 platform, is the backslash for UNIX?

0
 
wilcoxonCommented:
Don't think so.  I'm pretty sure the \& says to pass a code ref to errmode.  However, if errmode has a prototype or something it might be auto-interpreting it as a code-ref without the \.
0
 
lormandAuthor Commented:
I tested it on a running device which accepts a telnet connection but it still emails the notification using the following syntax.

  use Net::Telnet;
  use Socket;
  $telnet = new Net::Telnet ( Timeout=>3);
  $telnet->errmode(mail($script = "Error opening   connection to $IP"));
   $telnet->open($IP);

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now