I have a "check for bad" ping script here that works but it cuts
off the last bad IP address when it emails me. The file (called myfil in the script) that
I am writing the bad ping addresses shows all the IP addresses.
For example the 4 IP addresses below do not ping and my output file
shows:
888.333.333.33
156.343.333.99
888.323.222.223
888.222.222.111
BUT my email message excludes the last bad IP address (in this case
888.222.222.111) such as:
888.333.333.33
did not respond.
156.343.333.99
did not respond.
888.323.222.223
did not respond.
Here is my script. I know it is something with my send mail
part that is cutting out my output. Anyone have any suggestions???
@a = (<DATA>);
#$s = system("$?");
$myfil = "myfil";
foreach (@a)
{
system("/usr/sbin/ping $_");
if ( $? != 0)
{
open(FIL,">>$myfil") || "Can't open $myfil: $! \n";
print FIL "$_ did not respond.\n";
}
else
{
print "good\n";
}
}
system("cat $myfil | mailx -s 'Did not ping mail' myemail\@here\.com")
+;
system("rm myfil");
close(FIL);
close(DATA);
__DATA__
888.333.333.33
156.343.333.99
888.323.222.223
888.222.222.111
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.