- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell script - ping list of hostname
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
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
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
тАО11-07-2000 07:23 AM
тАО11-07-2000 07:23 AM
I have a list of hostnames in a text file (1 host to each line) and I would like some help on writing a script that could ping each of these hostnames and report back which hosts did not respond?
Sorry, but so far I have no idea how to start this... So I thought I'd post this as I browse through Essential SysAdm for any tips... thanks people!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 07:30 AM
тАО11-07-2000 07:30 AM
Re: shell script - ping list of hostname
for HOSTNAME in hosta hostb hostc hostd
do
ping $HOSTNAME -n 1
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 07:31 AM
тАО11-07-2000 07:31 AM
Solution#!/bin/sh
LANG=C
HOSTNAME_FILE=..... # insert here your file
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 07:32 AM
тАО11-07-2000 07:32 AM
Re: shell script - ping list of hostname
for HOSTNAME in `more /tmp/hostname.txt`
do
ping $HOSTNAME -n 1
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 07:35 AM
тАО11-07-2000 07:35 AM
Re: shell script - ping list of hostname
for i in ` cat (your file with hosts) `
do
ping $i -n 1 | grep -q "100%"
if [[ $? = 0 ]]
then
print " network $i not reachable"
fi
done
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 07:35 AM
тАО11-07-2000 07:35 AM
Re: shell script - ping list of hostname
script
ping host1 64 5
ping host2 64 5
ping host3 64 5
I then run the script and redirect stderr and stdout to a file and then go look at the file to determine what responded and what didn't.
to run the script:
./script > script.out 2>&1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 07:39 AM
тАО11-07-2000 07:39 AM
Re: shell script - ping list of hostname
thanks to everyone...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 07:42 AM
тАО11-07-2000 07:42 AM
Re: shell script - ping list of hostname
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 07:44 AM
тАО11-07-2000 07:44 AM
Re: shell script - ping list of hostname
#!/usr/bin/sh
while read HOST
do
ping $HOST -n 3
done < /tmp/ping.lst
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 01:21 PM
тАО11-07-2000 01:21 PM
Re: shell script - ping list of hostname
#!/usr/bin/sh
##
###
####
#####
for x in `cat /etc/hosts | awk ' $1 !~ /^#/ { print $1 } '`
do
ping $x -n 5
if [ $? -ne 0 ]
then
grep $x /etc/hosts
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2000 02:46 PM
тАО11-07-2000 02:46 PM
Re: shell script - ping list of hostname
PING=`ping $SERVER -n 1|grep %| awk '{print $7}'`
if [ ${PING%%} = 0 ]
then
echo ping test succeeded
else
echo ping test failed
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2000 02:45 AM
тАО11-08-2000 02:45 AM
Re: shell script - ping list of hostname
You might want to have a look at the perl script DOWNTIME. Visit WWW.FRESHMEAT.NET for the exact URL. This script does exactly that what you need.
Good luck !