- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: scripting and ping
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
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
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
тАО07-17-2002 01:51 AM
тАО07-17-2002 01:51 AM
OK I wanna do a ping but only once.
what I do is ping [IPADRESSS} 56 1
it works fine but how can I verify if it is not working? I have to send an interrupt when it fails.
How can I do this in a script
Thanks in advance
Andi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2002 01:58 AM
тАО07-17-2002 01:58 AM
Re: scripting and ping
There are a lot of posts about this. Just do a "script ping" search on the forums.
One good example :
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x7401a24d9abcd4118fef0090279cd0f9,00.html
Regards,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2002 02:08 AM
тАО07-17-2002 02:08 AM
Re: scripting and ping
you can simply check the return code of your ping- command:
ping ip_adress 56 1
if test $? -eq 0
then
:
else
exit 1
fi
this should do it for you.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2002 02:24 AM
тАО07-17-2002 02:24 AM
Re: scripting and ping
host_name=hosts
for host in $(cat $host_name)
do
/etc/ping $host -n 1 | grep -q '1 packets received'
if [ $? = 0 ]
then
echo "$host" >> /success
else
echo "$host" >> /failure
fi
done
Your variable host_name contains the host names in the file hosts that you wish to ping
grep -q - waits for the return of 1 packet received then goes to the next host in the file
$? is the return value
0 = succesful ping
1 = unsuccesful ping
HTH
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2002 02:56 AM
тАО07-17-2002 02:56 AM
Re: scripting and ping
it is of course a personal matter which solution you prefer. The attached script checks on "100% package loss" in the ping attempt.
In case the attached script is used for pinging more than a single machine, it is important to delete the file to which the output of the ping command is redirected: you have to make sure that the content of this file actually comes from the machine you ping.
regards
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2002 03:22 AM
тАО07-17-2002 03:22 AM
Re: scripting and ping
but This I allready knew, the thing I wanted to know is how I can set a timeout for a ping.
let's say it should try it for 1 second and if the ping does not come back the return value should be 1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2002 03:59 AM
тАО07-17-2002 03:59 AM
Solution- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2002 05:24 AM
тАО07-17-2002 05:24 AM
Re: scripting and ping
HTH
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2002 05:35 AM
тАО07-17-2002 05:35 AM
Re: scripting and ping
This will timeout after 5 seconds; silently returns 0 if ok
ping.pl -t 5 remotehost
STAT=$?
if [ ${STAT} -eq 0 ]
then
echo "Ping ok"
fi
ping.pl -u will display full usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2002 12:50 AM
тАО07-18-2002 12:50 AM
Re: scripting and ping
I've tried it
ping IP -n1
will break after some time if the IP is not pingalbe. So I'd suggest to grep for the line package loss and check if it is 0% or 100%?
ping sensles_ip -n 1 |grep "packet loss" |awk '{print $7}' |cut -f1 -d"%"
will answer with 100
ping reachable_ip -n 1 |grep "packet loss" |awk '{print $7}' |cut -f1 -d"%"
will give you 0
You could then compare the result with an if statement.
What do you think.
HTH
Rainer