I'm playing around with PERL, never used it before and find some of the example scripts I run across to be useful - while I'm gearing up to spare free cycles to learning how to code properly. However, I found one on this site that I'm trying to modify slightly: The following is code:

use strict; use Net::Ping; # Declare Var my ($host, $x, $res); my $output = ''; # Servers To Ping my @AFIS = qw( mnbcamp001 mnbcamp002 mnbcamp003 mnbcamp004 mnbcamp005 ); # Ping Hosts Defined Above sub ping_hosts { foreach $host (@AFIS) { my $p = Net::Ping->new("icmp"); my $res = $p->ping($host); $output .= "Unknown $host\n" unless defined $res; if (!$res) { $output .= "$host Host is not reachable!\n"; } else { $output .= "$host Host is reachable!\n" } } } ping_hosts; # Print Results to Terminal print $output;

The script itself works but what I'd like to have happen is two things: Since I have about 85 servers that will be pinged via this method, I'd like to supply it with a text file which has the server names and/or IPs in it and secondly I'd like to have it output the data into a text file, and, if it's not super hard to do email it.

That being said, I did manage to add the output to file element but it gave me an uninitialized value in concatenation error for $res

Added where seemed appropriate

my $outfile = "output.txt"; open (OUTFILE, ">> $outfile") || die "ERROR: opening $outfile\n"; chomp ($host); print OUTFILE "Results for $host:\n"; print OUTFILE "$results\n\n";

Now, I'm a total newb, I'm just digging into this little bits at a time and playing around with things. Please, take it easy on me, I've got literature coming in the mail soon but figured why not ask a question and see what happens in the meantime. I appreciate any help I can get!


In reply to Newbie - Playing Around by rts1676

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.