Advertisement

12.29.2004 at 12:13PM PST, ID: 21256736
[x]
Attachment Details

Reading from a file

Asked by holein5 in Perl Programming Language

Tags: ping, down, perl

I have the following code (It probably needs changed too, but I'm learning). I want to ping a server, check to see if the server is down, and if it is, say so (I am going to call an external program later, but right now I just want to print it). My thought was to ping the server, pipe the output to a text file and look for the word "Out" as in "Request Timed Out". Here's what I have so far. It looks like my text is getting into the array, but I am having problems with testing it. I sure would appreciate some assistance:

#!/perl

use strict;
use warnings;
use vars qw/ $device @raw_data $line /;

# $device = shift or die;
$device = "localhost";  # here I put a device or IP to check..

`ping -n 1 $device > $device.txt`;
open(FILE, "$device.txt") || die("Could not open file!");
@raw_data = <FILE>;
close(FILE);

foreach $line (@raw_data)
    {
        chomp($line);
        if ($line = "out") {
            print("$device failed ping test");
        }
    }
# `del $device.txt`;
Start Free Trial
[+][-]12.29.2004 at 12:20PM PST, ID: 12921711

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 12:31PM PST, ID: 12921785

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 12:38PM PST, ID: 12921841

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 12:43PM PST, ID: 12921876

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 12:45PM PST, ID: 12921897

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 12:58PM PST, ID: 12921983

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 01:03PM PST, ID: 12922006

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 01:14PM PST, ID: 12922079

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 01:16PM PST, ID: 12922089

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 01:20PM PST, ID: 12922114

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: ping, down, perl
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 3
Solution Grade: A
 
 
[+][-]12.29.2004 at 01:21PM PST, ID: 12922121

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 01:22PM PST, ID: 12922131

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.30.2004 at 05:16AM PST, ID: 12925615

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32