944,159 Members | Top Members by Rank

Ad:
Jun 6th, 2006
0

Ping Script

Expand Post »
Hello, I am writing a script that is going to ping a remote host but I want the user to be able to enter in the interval and size when he runs the program. For example the user would enter this to initialize the script.

Quote ...

./mping -i 0.05 -s 804
The code that I have running so far is:

Quote ...

#!/bin/bash
host=db.macom.com
ping $host $1 $2 $3 $4
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mcrosby is offline Offline
6 posts
since May 2006
Jun 7th, 2006
0

Re: Ping Script

Why do you want a user intervention in your script ??

Just a suggestiion, If you want to collect data over a certain interval of time then use the -w option to define the interval and that will remove the user intervention.

As far as your comparision of Tx and Rx packets is concerned, you can capture the ping statistics in a log file and then use 'awk' to get the Tx packet in one variable and Rx packets in one variable from the logfile and compare them as per your requirement.

Amit
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kamitsin is offline Offline
16 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: ftp and compare script
Next Thread in Shell Scripting Forum Timeline: Help with getopt/getopts





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC