The two operations you perform in your script, pinging a remote host and sending an email, can and probably should be done from within Perl, using the Net::Ping and MIME::Lite modules. This gives you several advantages:
- The buffering issues you are presently encountering will cease to be a problem;
- No need to create temporary files;
- Flexibility -- a pure-Perl implementation will be much easier to adapt to different situations than a Perl/Unix hybrid;
- Portability -- If you want to run your Ping reporter from Windows, you need something that doesn't rely on Unix system calls.
With that said, consider using something like the following code:
#! /usr/bin/perl
use strict ;
use warnings ;
use MIME::Lite ;
use Net::Ping::External qw/ ping / ;
# Ping all the IP addresses.
my $output = '' ;
while ( <DATA> )
{
chomp ;
next unless $_ ;
$output .= "$_: " . ( ping( host => $_ ) ? 'OK' : 'FAILED' ) . "\n
+" ;
}
# Compose & send the email.
my $msg = MIME::Lite->new(
From => 'somemail@example.com',
To => 'yourmail@example.com',
Subject => 'Ping Report',
Data => $output
) ;
$msg->send ;
__DATA__
888.333.333.33
156.343.333.99
888.323.222.223
888.222.222.111
_______________
D
a
m
n
D
i
r
t
y
A
p
e
Home Node
|
Email
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.