
francc
New User
Dec 27, 2012, 9:05 AM
Post #1 of 3
(3034 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...
|