- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 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-01-2007 05:48 AM
08-01-2007 05:48 AM
For - Write a script that will ping a list of hosts and return how many are 'alive'.
I am trying out the following :
cat /etc/hosts|awk '{print $2}'|sort -u|grep -v ^$|xargs ping
it gives me the following error :
ping: bad timeout:hostname
when I pass the above command to a variable I get :
host1 host2 host3 host4
with no carriage returns . How do I overcome this.
Thanks.
Solved! Go to Solution.
- Tags:
- ping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 05:49 AM
08-01-2007 05:49 AM
Re: ping script
the result :
host1 host2 host3 is when I do echo $VAR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 05:52 AM
08-01-2007 05:52 AM
Re: ping script
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1149721
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 06:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 06:22 AM
08-01-2007 06:22 AM
Re: ping script
# cat /etc/hosts | egrep -v '^#|^$' | xargs -n1 -i ping {} -n 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 06:36 AM
08-01-2007 06:36 AM
Re: ping script
#!/usr/bin/sh
HOSTS="huey louie dewey"
for HOST in ${HOSTS}
do
ping.pl -t 5 -n 3 ${HOST}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "${HOST} is alive."
else
echo "${HOST} failed; status ${STAT}." >&2
fi
done
--------------------------------------
Invoke as ping.pl -u for full usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 06:45 AM
08-01-2007 06:45 AM
Re: ping script
for i in `cat hosts`
do
ping $i -n 1 | grep "0%" >/dev/null
t=`echo $?`
ttl=`expr $ttl + $t`
done
echo "there are $ttl hosts alive..."
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 07:26 AM
08-01-2007 07:26 AM
Re: ping script
Thanks All for replying , I am looking at Sandman's solution ,
what does -n1 and -i signify. Please throw some light on this please.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 07:30 AM
08-01-2007 07:30 AM
Re: ping script
> what does -n1 and -i signify
I suggest that you consult the manpages. You will learn more by researching questions like this yourself.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 07:33 AM
08-01-2007 07:33 AM
Re: ping script
More than anything, it signifies that you are too lazy/unmotivated/uninformed/... to do a "man xargs". Unless you learn to use the man pages well, you will never have a very successful career in UNIX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 07:39 AM
08-01-2007 07:39 AM
Re: ping script
~hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 07:55 AM
08-01-2007 07:55 AM
Re: ping script
LOL
-i is insert the previous stdout
-n uses number of arguments to pass from the previous stdout
good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2007 03:39 PM
08-01-2007 03:39 PM
Re: ping script
awk '{print $2}' /etc/hosts |sort -u|grep -v ^$|xargs ping
grep -v -e '^#' -e '^$' /etc/hosts | xargs -n1 -i ping {} -n 2
$ for i in $(< /etc/hosts ); do
- Tags:
- evil cat