Differences between version 2 and previous revision of CyberLeo/Scraps/PingyThing.
Other diffs: Previous Major Revision, Previous Author
Newer page: | version 2 | Last edited on Sunday, 4 July 2010 18:08:27 | by CyberLeo | Revert |
Older page: | version 1 | Last edited on Sunday, 4 July 2010 18:07:44 | by CyberLeo | Revert |
@@ -1,17 +1,17 @@
-Target:
+!
Target:
# Generate a list of timestamp/RTT values, one per second, into a text file suitable for later processing and graphing
-Limitations:
+!
Limitations:
# Utilize base system; don't require extra packages
# Operate in 'streaming' mode: don't use bourne shell 'while' loop and keep fork()ing to a minimum
-Result:
+!
Result:
<code brush="bash">
ping -n 172.16.44.18 | sed -le 's/^.* \(time=[0-9.]*\) ms$/\1/; /^time=/!d; s/^time=//g; /\./!s/$/./g; /\.[0-9][0-9][0-9]$/!s/$/0/g; /\.[0-9][0-9][0-9]$/!s/$/0/g; /\.[0-9][0-9][0-9]$/!s/$/0/g; s/\.//g' | awk '{ printf; printf " "; system("date +%s"); close("date"); fflush() }'
</code>
-Breakdown:
+!
Breakdown:
* Sed portion:
<code brush="sed">
s/^.* \(time=[0-9.]*\) ms$/\1/; # Trim out all but the RTT
/^time=/!d; # Eliminate all other lines
version 2
Target:
- Generate a list of timestamp/RTT values, one per second, into a text file suitable for later processing and graphing
Limitations:
- Utilize base system; don't require extra packages
- Operate in 'streaming' mode: don't use bourne shell 'while' loop and keep fork()ing to a minimum
Result:
ping -n 172.16.44.18 | sed -le 's/^.* \(time=[0-9.]*\) ms$/\1/; /^time=/!d; s/^time=//g; /\./!s/$/./g; /\.[0-9][0-9][0-9]$/!s/$/0/g; /\.[0-9][0-9][0-9]$/!s/$/0/g; /\.[0-9][0-9][0-9]$/!s/$/0/g; s/\.//g' | awk '{ printf; printf " "; system("date +%s"); close("date"); fflush() }'
Breakdown:
- Sed portion:
s/^.* \(time=[0-9.]*\) ms$/\1/; # Trim out all but the RTT /^time=/!d; # Eliminate all other lines s/^time=//g; # Remove the 'time=' tag; want only the number /\./!s/$/./g; # Add a decimal point onto the end if it doesn't exist /\.[0-9][0-9][0-9]$/!s/$/0/g; # Add a 0 to the end if there are fewer than three digits after the decimal point /\.[0-9][0-9][0-9]$/!s/$/0/g; # Add a second 0 /\.[0-9][0-9][0-9]$/!s/$/0/g; # Add a third 0; now the number should be normalized to microseconds s/\.//g; # Remove the decimal point, leaving only an integer number of microseconds
- Awk portion:
{ printf; # Print out the RTT printf " "; # Print a space system("date +%s"); # Print the current seconds-since-epoch close("date"); # A kludge, but there's no other way to acquire the date without using gawk or calling 'date' somehow fflush(); # Line-buffer the output }