So I have written shell script to ping a web server 86,400 times and write the output into a text file. Example of one ping below:

64 bytes from a104-100-153-112.deploy.static.akamaitechnologies.com ( icmp_seq=1 ttl=60 time=12.6 ms
64 bytes from a104-100-153-112.deploy.static.akamaitechnologies.com ( icmp_seq=2 ttl=60 time=17.2 ms
64 bytes from a104-100-153-112.deploy.static.akamaitechnologies.com ( icmp_seq=3 ttl=60 time=11.0 ms

My first issue is I then need it to extract the value of the round trip (12.6) time from the raw ping output into a second text file. What I have right now I believe will ignore the decimal point in 12.6 and only take in the numerical values. My code below:

sed 's/.* time= \ ([0-9]* \ ). * /\1/' pingoutput.txt | sort -n > sortedtime.txt

After extracting those time values into sortedtime.txt I read the text file and make each line (so each round trip time) into an element in a list called timelist[]. It then prints both the length and the entire list to assure that the list took in all 86400 roundtrip times and they were sorted correctly. My code below:

    with open("sortedtime.txt", 'r') as time:
         timelist = []
         for line in time:

   print timelist[0:86399]
   print len(timelist)

My second and last issue is I need to plot a CDF of all my values in that timelist list and display it. I am new to Python and am not too familiar with the matplotlib.pyplot package and, so I don't understand how I would go about plotting the list elements on the x axis vs a 0 to 1 y axis.

I am working in Linux, any help is greatly appreciated!

  • For your first half of the problem, rather than use sed, I'd use awk. awk -F '=' '{ print $NF ]' sortedtime.txt | awk '{ print $1}' – Stephan Sep 28 '16 at 22:59
  • I'm not sure I see the necessity of sorting the data - shouldn't it just be a matter of calling the hist plot function with cumulative=True? See for example statistics example code: histogram_demo_cumulative.py – steeldriver Sep 29 '16 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.