
1st June 2006, 16:07
|
|
Junior Member
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ping script
hello, I am looking to make a script that will ping a remote ip address. Upon completion of the ping I want the program to either ping again if the # of packets transmitted is equal to the number of packets received or exit if the two values are unequal and information was lost. I am not sure if I should go about this program with a shell script or a C script or any other alternative. In either case would someone be able to point me in the correct direction?
|

1st June 2006, 17:50
|
|
Super Moderator
|
|
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
|
|
If you use a shell script, you might have to parse the ping output with awk and/or sed.
But it might be easier to use a PHP script for it. Have a look at the functions exec(), system(), shell_exec, and passthru().
|

1st June 2006, 18:24
|
|
Junior Member
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am very new to scripting so to put it bluntly I have no idea what you are talking about lol..I am familiar with PHP but i do not know how to code it. Are those functions I should take a look at in PHP or shell script
|

2nd June 2006, 00:12
|
|
Pseudo Lawyer
|
|
Join Date: Apr 2006
Location: Switzerland
Posts: 857
Thanks: 3
Thanked 25 Times in 23 Posts
|
|
The commands that falko posted are php native functions
http://ch2.php.net/manual/en/ref.exec.php
Last edited by sjau; 2nd June 2006 at 00:21.
|

5th June 2006, 15:02
|
|
Junior Member
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok so i wanted to use bash scripting and i received a bit of help thus far.
Quote:
#!/bin/bash
host=yahoo.com
echo "Pinging $host ; Use ctl c to end the loop"
while : ; do
info=$(ping -qc3 $host |grep packets| cut -d" " -f1,4)
set -- $info
#echo $1 $2
if [ $1 != $2 ]; then
echo "transmitted and received packets don't match, exiting now"
exit
else
echo "transmitted and received packets do match, repeating loop"
fi
done
|
but i am looking to get the program to display the results in the terminal window. I would like it to display the normal ping information the size as well as the interval. I would also like it so that when the user runs the program they would do "nameofprogram -c3 -i0.05 -s800 ... so they take those commands from the command line and then the output is the size, the interval, and the packet size and then it gives the message if they are equal or not can anyone help?
|

5th June 2006, 15:51
|
|
Super Moderator
|
|
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
|
|
Quote:
|
Originally Posted by mcrosby
I would also like it so that when the user runs the program they would do "nameofprogram -c3 -i0.05 -s800 ... so they take those commands from the command line and then the output is the size, the interval, and the packet size and then it gives the message if they are equal or not can anyone help?
|
Have a look here: http://www.tldp.org/LDP/abs/html/int...s.html#ARGLIST
|

5th June 2006, 16:31
|
|
Junior Member
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hmm that page would help more if there were discriptions of what they were doing
|

5th June 2006, 19:47
|
|
Super Moderator
|
|
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
|
|
You can refer to arguments you pass to your script with $1, $2, ... $0 is the script itself.
|

5th June 2006, 20:56
|
|
Junior Member
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks Falco that did in fact prove to help
|

6th June 2006, 15:04
|
|
Junior Member
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok so now for example my output is:
Quote:
64 bytes from host: icmp_seq=0 ttl=64 time=2.22 ms
64 bytes from host: icmp_seq=1 ttl=64 time=0.537ms
64 bytes from host: icmp_seq=2 ttl=64 time=0.575 ms
64 bytes from host: icmp_seq=3 ttl=64 time=0.585 ms
64 bytes from host: icmp_seq=4 ttl=64 time=0.578 ms
|
And then once the ping either times out or the user presses cntrl C you get
Quote:
5 packets transmitted, 5 received, 0% packet loss, time 12009ms
etc...
|
My question is how do I reference that number of packets transmitted and received so that I can calculate if they are equal or not. I know i would put those values into variables but what do I set each variable equal too?
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 15:43.
|
Recent comments
2 hours 6 min ago
7 hours 55 min ago
9 hours 46 min ago
11 hours 31 min ago
15 hours 21 min ago
21 hours 6 min ago
21 hours 17 min ago
1 day 1 hour ago
1 day 7 hours ago
1 day 12 hours ago