Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Well I thought I had some stuff figured out and after another 15 hours of reading/testing I haven't gotten much further.

I thought the ping part was working but now it seems intermittent, and I still can not get the foreach part to work. Basically I do not want to email a failure notive about the same failed ping to a host/IP until some time has passed, maybe 2-3 failures or something. While trying to ping once every 5 minutes. I have tried literally dozens of different ways to skip over the IP if it is on the email.list -- unless ($_ =~ my @eFile) -- was my last attempt but I can't get anything to work there.

Any assistance is appreciated, thanks Sam.

#!/usr/local/bin/perl use strict; use warnings; use Net::Ping; use Net::SMTP; my $from = 'from@email.com'; my $site = 'email.com'; my $smtp_host = 'smtp.email.com'; my $to = 'to@email.com'; my $smtp = Net::SMTP->new($smtp_host, Hello => $site); my $oFile = open(oFILE, ">", "output.file") or die("unable to write to + $!\n"); my $hFile = open(hFILE, "<", "host.file") or die("unable to open $!\n" +); my @ip_array = <hFILE>; chomp(@ip_array); my $eFile = open(eFILE, ">", "email.file") or die("unable to write to +$!\n"); my @efile = <eFILE>; chomp(@efile); sub email { $smtp->mail($from); $smtp->to($to); $smtp->data(); $smtp->datasend("To: $to\n"); $smtp->datasend("Subject: Ping failure notice.\n"); $smtp->datasend("\n"); $smtp->datasend("Ping failed on host $_\n"); $smtp->dataend; print eFILE ("$_\n"); } my $p = Net::Ping->new(); foreach (@ip_array) { if($p->ping($_)) { print oFILE ("$_ is responding to ping.\n"); } else { print oFILE ("$_ is NOT responding to ping.\n"); unless ($_ =~ my @eFile) { email(); } } } close(hFILE); close(oFILE); close(eFILE); $p->close(); $smtp->quit; #End of Code
The files I am using: --host.file-- www.cnn.com 127.0.0.1 10.10.10.1 178.23.1.2 9.1.1.1> --email.file-- <empty> --output.file-- <empty>

In reply to Re^2: Trouble with Array or ?? by Anonymous Monk
in thread Trouble with Array or ?? by Anonymous Monk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-19 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found