•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 425,932 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,655 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 7565 | Replies: 1
![]() |
•
•
Join Date: May 2006
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
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.
The code that I have running so far is:
ok so now for example my output is:
And then once the ping either times out or the user presses cntrl C you get
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?
•
•
•
•
./mping -i 0.05 -s 804
The code that I have running so far is:
•
•
•
•
#!/bin/bash
host=db.macom.com
ping $host $1 $2 $3 $4
ok so now for example my output is:
•
•
•
•
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
•
•
•
•
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?
•
•
Join Date: Apr 2006
Location: India
Posts: 16
Reputation:
Rep Power: 3
Solved Threads: 0
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
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- DOS Batch command to ping network IP (Legacy and Other Languages)
- Tidy up output of ping. (PHP)
- ASP slow-down server script (ASP)
Other Threads in the Shell Scripting Forum
- Previous Thread: ftp and compare script
- Next Thread: Help with getopt/getopts


Linear Mode