#1  
Old 1st June 2006, 15:07
mcrosby mcrosby is offline
Junior Member
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
Reply With Quote
Sponsored Links
  #2  
Old 1st June 2006, 16:50
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

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().
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 1st June 2006, 17:24
mcrosby mcrosby is offline
Junior Member
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4  
Old 1st June 2006, 23:12
sjau sjau is offline
Local Meanie
 
Join Date: Apr 2006
Location: Switzerland
Posts: 1,146
Thanks: 4
Thanked 55 Times in 51 Posts
Default

The commands that falko posted are php native functions

http://ch2.php.net/manual/en/ref.exec.php

Last edited by sjau; 1st June 2006 at 23:21.
Reply With Quote
  #5  
Old 5th June 2006, 14:02
mcrosby mcrosby is offline
Junior Member
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
Reply With Quote
  #6  
Old 5th June 2006, 14:51
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

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
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #7  
Old 5th June 2006, 15:31
mcrosby mcrosby is offline
Junior Member
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm that page would help more if there were discriptions of what they were doing
Reply With Quote
  #8  
Old 5th June 2006, 18:47
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

You can refer to arguments you pass to your script with $1, $2, ... $0 is the script itself.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #9  
Old 5th June 2006, 19:56
mcrosby mcrosby is offline
Junior Member
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks Falco that did in fact prove to help
Reply With Quote
  #10  
Old 6th June 2006, 14:04
mcrosby mcrosby is offline
Junior Member
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

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?
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ping problem !! kong121s Installation/Configuration 8 10th May 2006 07:28
Firewall script ColdDoT Server Operation 1 8th May 2006 23:50
Suggestion: Use mySQL script for installation Dee General 1 17th February 2006 10:02
Internal Server Error 500 cgi script mphayesuk General 6 8th February 2006 22:53
DNS - call script to created named.conf entries on secondaries cstone Installation/Configuration 4 15th September 2005 01:16


All times are GMT +2. The time now is 06:03.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.