|
| 1 | +## Find the five longest ping response time from google.com |
| 2 | + |
| 3 | +Lets do it in some steps |
| 4 | + |
| 5 | +Creating a new file |
| 6 | + |
| 7 | + touch tmp |
| 8 | + creates a file named tmp in your present working directory |
| 9 | + |
| 10 | +Using ping command |
| 11 | + |
| 12 | + ping google.com |
| 13 | + ping command is used to ping a server using ICMP ECHO_REQUESTS to network hosts |
| 14 | + |
| 15 | +Redirecting the ping data and running it in background |
| 16 | + |
| 17 | + ping google.com > tmp & |
| 18 | + > is used to redirect the ping data into the text file tmp |
| 19 | + & makes the entire process to run in background |
| 20 | + |
| 21 | +Extracting the required data |
| 22 | + |
| 23 | + |
| 24 | + using awk and cut, |
| 25 | + |
| 26 | + awk '{print $8}' tmp |
| 27 | + http://www.grymoire.com/Unix/Awk.html |
| 28 | + awk is rather a programing language specilized in manupilating text files |
| 29 | + here awk is used to printout only the coloumn no 8 of the text file named 'tmp' |
| 30 | + |
| 31 | + awk '{print $8}' tmp | cut -d “=” -f2 |
| 32 | + cut - remove sections from each line of files |
| 33 | + here we trying to extarct only the numbers |
| 34 | + delimiter option -d |
| 35 | + field option -f |
| 36 | + |
| 37 | + using grep and cut, |
| 38 | + |
| 39 | + cat tmp | grep -Po 'time.*.ms' |
| 40 | + grep is a command used to search for a given pattern inside a text file |
| 41 | + text content of the temp file is piped to grep command |
| 42 | + -P enabling regex (perl regex) |
| 43 | + -o print only matching |
| 44 | + |
| 45 | + cat tmp | grep -Po 'time.*.ms' | cut -d "=" -f 2 |
| 46 | + |
| 47 | + |
| 48 | + cat tmp | grep -Po 'time.*.ms' | cut -d "=" -f 2 | cut -d " " -f 1 |
| 49 | + |
| 50 | + |
| 51 | +Finding the longest |
| 52 | + |
| 53 | + awk '{print $8}' tmp | cut -d “=” -f2 | sort |
| 54 | + |
| 55 | + sort - sort lines of text |
| 56 | + |
| 57 | + awk '{print $8}' tmp | cut -d “=” -f2 | sort | uniq |
| 58 | + |
| 59 | + uniq - removes adjacent duplictes after sort |
| 60 | + |
| 61 | + awk '{print $8}' tmp | cut -d “=” -f2 | sort | uniq | tail -n 5 |
| 62 | + |
| 63 | + tail - used to output the last part of file |
| 64 | + last n lines using -n option |
| 65 | + |
| 66 | + Or using grep |
| 67 | + |
| 68 | + cat tmp | grep -Po 'time.*.ms' | cut -d "=" -f 2 | cut -d " " -f 1 | sort | uniq | tail -n 5 |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
0 commit comments