?
Solved

how do I email notification if telnet session fails to open

Posted on 2003-03-28
6
Medium Priority
?
148 Views
Last Modified: 2010-03-05
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
Comment
Question by:lormand
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 300 total points
ID: 8226131
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
 

Author Comment

by:lormand
ID: 8226221
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
 
LVL 26

Expert Comment

by:wilcoxon
ID: 8226782
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:lormand
ID: 8227330
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
 
LVL 26

Expert Comment

by:wilcoxon
ID: 8227413
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
 

Author Comment

by:lormand
ID: 8227679
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question