I have a script that pings a URL and mails if there are particular no. of failures. The URLs and the no. of failures before which the email has to be sent are specified in a text file.

What i want to do is next to the URLs i want to specify the Email addresses to which the failures are to be mailed. How can i read them from the text file itself.

Also I want to create a log file after a certain no. of failures. How can I do that ?

Mailing is not a problem as i can use Email::Send::Gmail for it. I am posting my script below. Kindly Help. Thanx in advance.
#!/usr/bin/perl use warnings; use LWP::Simple; use Email::Send; use Email::Send::Gmail; use Email::MIME::Creator; use Net::Ping::External qw(ping); use Tie::File; my $testfolder = "/Users/Appy/Desktop/"; my $to = "test1\@gmail.com"; my $from = "test2\@gmail.com"; my $subject = "Uris not responding."; my $count = 1; tie @file, 'Tie::File', $testfolder . "testfile.txt" or die; foreach $URL (@file) { my $string1 = $URL; if ( $string1 =~ m/ # Match ping\s # 'ping ' /ix # i = Ignore case # x = allow the regexp to go over multiple line +s ) { my $URI = substr $URL, 8; print "$URI\n"; sub myping { my $alive = ping(host => "$URI"); if ($alive) { print "$URI is active.\n"; } else { my $c = substr $URL, 5, 2; $count = $count + 1; if ($count <=round($c/2)) { &myping; } if ($count=$c) { ##create a log file } } }
Testfile

ping 07 abc.in a@b.com,c@d.com

ping 05 google.co.in e@f.com,g@h.com

s include the respective email addresses to which notification is to be sent. and the numbers specify the no. of failures after which the email has to be sent


In reply to Reading Email List from a text file by Appy16

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.