- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ping script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 04:03 AM
08-23-2002 04:03 AM
I would like to write a script that would ping multiple servers. Any help is greatly appreciated. POints will be assigned.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 04:14 AM
08-23-2002 04:14 AM
Re: ping script
for server in serv1 serv2 serv3
do
/etc/ping $server -n 3 > $server.ping
done
grep -l "100% packet loss" *.ping | cut -d"." -f1
this will give you the list of server you cannot ping
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 04:21 AM
08-23-2002 04:21 AM
Re: ping script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 04:25 AM
08-23-2002 04:25 AM
Re: ping script
So if you have your hosts in a file as a list, then
cat THATFILE | xargs -i ping {} -n 1
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 04:26 AM
08-23-2002 04:26 AM
Re: ping script
for server in server1 server2
do
/etc/ping $server -n 3
done
Regards,
Hilary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 04:36 AM
08-23-2002 04:36 AM
Re: ping script
Just a suggestion in addition to the good answers already given...
I'd go with "-n 3" to ping each server 3 times instead of just once. The script I wrote to ping remote locations would often give false failures when only sending 1 packet. I don't know the last time I had a false failure since I changed to send 3 packets.
It only takes 2 more seconds per location to send 3 packets than to send 1 even if there is no response.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 05:15 AM
08-23-2002 05:15 AM
Re: ping script
Very GOOD point!
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 05:37 AM
08-23-2002 05:37 AM
Re: ping script
Here's an example in perl
l1:/tmp 103 # cat xx
#!/pro/bin/perl -w
use Net::Ping;
my $icmp = Net::Ping->new ("icmp", 1);
my $tcp = Net::Ping->new ("tcp", 1);
my $udp = Net::Ping->new ("udp", 1);
my @hosts = qw(
l1
pc09
127.0.0.1
);
my %inet;
for my $ip (@hosts) {
$icmp->ping ($ip) and $inet{$ip}{icmp} = 1;
$tcp->ping ($ip) and $inet{$ip}{tcp} = 1;
$udp->ping ($ip) and $inet{$ip}{udp} = 1;
}
$icmp->close;
$udp->close;
$tcp->close;
print "IP address ICMP TCP UDP\n",
"-------------- ----- ----- -----\n";
for my $ip (@hosts) {
exists $inet{$ip} or next;
my %p = %{$inet{$ip}};
printf "%-14s%6s %6s %6s\n", $ip,
$p{icmp} ? "alive" : "- ",
$p{tcp} ? "alive" : "- ",
$p{udp} ? "alive" : "- ";
}
l1:/tmp 104 # perl xx
IP address ICMP TCP UDP
-------------- ----- ----- -----
l1 alive alive alive
pc09 alive alive alive
127.0.0.1 alive alive alive
l1:/tmp 105 #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:19 AM
08-23-2002 10:19 AM
Re: ping script
I read all these responses, but it seems that everyone has assumed that these server are all WORKING. If you try and automate this, and a server is down, ping will hang. I looked at the man pages, and don't see a timeout option. Maybe someone knows....
...continuing, you have another option:
Let's suppose your on a class C network 11.40.1.xx (same applies for A and B). You can ping the broadcast address (assume 255)(this might be a bad idea in your environment, but in mine, this isn't a problem).
For example,
/etc/ping 11.40.1.255 -n N > /tmp/myPingFile
Where "N" is larger than the largest number of hosts on your network. (If you have a large network you may not want to do this).
Any hosts that are down won't echo back. Then you can read myPingFile, grep out the IP address into nslookup to see what hosts are alive.
Then you can compare this long list to your short list with another grep or something.
Anyway, ping is not a very friendly tool if you don't get a directed response back.
I tend to think about what can go wrong, too!
Good luck!!
- Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:25 AM
08-23-2002 10:25 AM
Re: ping script
ping.pl -t 5 remote_host
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Host ok"
else
echo "Host Bad"
fi
and a timeout of 5 seconds is set.
Invoke it as ping.pl -u for full usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 11:39 AM
08-23-2002 11:39 AM
Re: ping script
Actually, down hosts are why you use the "-n" option. On my 11.0 servers, "ping down_host -n 1" will return (timeout) after 11 seconds. "-n 3" returns after 13 seconds.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 11:46 AM
08-23-2002 11:46 AM
Re: ping script
Yeah, I see that. If you have a bunch of hosts, that are down, this would still stink...
- Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 11:50 AM
08-23-2002 11:50 AM
SolutionHere you go here is the script:
#!/bin/sh
LANG=C
HOSTNAME_FILE=iphosts
for host in $(cat $HOSTNAME_FILE)
do
ping $host -n 1 | grep -q '1 packets received'
if [ $? = 0 ]
then
echo "$host: OK"
else
echo "$host: FAIL"
fi
done
and here is how it works ..
iphosts is a file that has the list of hostnames or ip address like so
host1
host1
192.168.10.xx
192.168.10.xx
now you run the script and it will check the host and go to the next one you will get the output to the screen. If you modify it a little you can even get the scrip to send you an email
~ Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2003 11:10 PM
01-20-2003 11:10 PM
Re: ping script
- shows if interface is up or down
- ping with config-file, which you can edit
etc etc
have a look at it ...
stg