CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
ping script for multiple host from host.txt

 



francc
New User

Dec 27, 2012, 9:05 AM

Post #1 of 3 (1285 views)
ping script for multiple host from host.txt Can't Post

Hey all.



As you can see, just registerd because i cannot findout how to solve this issue.

I have posted this also somewhere els, but no reply was given, so, why not ask the gurus ?

i have writen a script that does the following:



It uses a hostlist (hosts.txt) to read from and connect using a default username/password just for this issue.

The hostlist will conntain over 500 routers.

We need to know the latency of the connection. The script final command will be send to a Sun os 5 machine, with perl 5 installed.

We connect to that machine using secure crt.

The output of the script needs to be writen to a cvs file.

The idea is to run this script each week, so i am going to create a batch file to fire up the script. That batch file will be added to the taskmanager.



So far the easy part. Now thee bit of code, where i ame lost.

Can any of you verify if this script is correct?

=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=##=#=#=

#!/usr/bin/perl -w
use strict;
use Net::Ping;
use Text::CSV;

my $hostList = $ARGV[0];
if(!defined $hostList){
print “Usage: $0 \n”;
exit;
open(LIST, $hostList) or die “Can’t open hosts.txt file to load into array: $!”;
}
our @hosts = ;
close(LIST);
my $p=Net::Ping -s->new(“tcp”, 2);
my @data;
foreach my $host(@hosts){
chomp($host);
print “Pinging $host\n”;
unless($p->ping ($host)){
print “$host has failed: “,scalar(localtime),” \n”;
push(@data,“$host has failed: “,scalar(localtime),” \n”)
}else{
print “$host was a success: “,scalar(localtime),” \n”;
my $csv=Text::CSV->new(); # push MYFILE “field1;field2;field3\n”;
}
}

#Save in output file
my $output = “pinging “.scalar(localtime).”.csv”;
open(LIST, $output) or die “Can’t open output file to write the result: $!”;
foreach(foreach my $line(@data)
{

}
exit;

=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=##=#=#=

We have tested this in a windows envoriment, (no access jet to the actual machine where this is going to run) and it seems to be working.

Mine issue is if the "-s" option right after ping will work, and how to capture the replys of the "-s".

The machines will be all online, we just need to know the latancy...


FishMonger
Veteran / Moderator

Dec 27, 2012, 9:57 AM

Post #2 of 3 (1270 views)
Re: [francc] ping script for multiple host from host.txt [In reply to] Can't Post

In what ways does it "seems to be working"?

I'm sure it doesn't produce the expected output.

I see problems on the following lines.

10 - never gets executed
12 - @hosts is not assigned any values
14 - wrong syntax
24 - $csv is never used


Start by fixing those issues, then we can take a look at the other problems.


FishMonger
Veteran / Moderator

Dec 27, 2012, 10:03 AM

Post #3 of 3 (1266 views)
Re: [francc] ping script for multiple host from host.txt [In reply to] Can't Post


Quote
Mine issue is if the "-s" option right after ping will work, and how to capture the replys of the "-s".


Net::Ping doesn't have a "-s" method, so I have no clue what you expect that to accomplish.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives