home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume03 / times.awk < prev    next >
Encoding:
Internet Message Format  |  1988-09-11  |  4.4 KB

  1. From: genrad!ukma!david (David Herron, NPR Lover)
  2. Subject: uucp info from LOGFILE (awk script)
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 15
  7. Submitted by: ukma!david (David Herron)
  8.  
  9.  
  10. Here's a source I just wrote this evening.  It's short and self-explanatory ---
  11.  
  12. --- David Herron
  13. --- ARPA-> ukma!david@ANL-MCS.ARPA
  14. --- UUCP-> {ucbvax,unmvax,boulder,oddjob}!anlams!ukma!david
  15. ---        {ihnp4,decvax,ucbvax}!cbosgd!ukma!david
  16.  
  17. Hackin's in me blood.  My mother was known as Miss Hacker before she married!
  18.  
  19. -------------------------------------------------------------
  20. # uucp.times.awk -- read a uucp LOGFILE and find out how long
  21. # we spent talking to particular places.  (Also, remembers if
  22. # the time spent was our call or their call).
  23. #
  24. # This is nice for: 1) Knowing when you made long distance
  25. # calls and where to, 2) knowing how much of the load between
  26. # you and some sites you're carrying.
  27. #
  28. #
  29. # This works with the UUCP log file format produced by the
  30. # uucp delivered with BRL Release 3.  (i.e. 4.2BSD, i.e. that
  31. # *extremely* hacked up conglomeration of uucp's that prompted
  32. # the writing of honey-danber). 
  33. #
  34. #
  35. # USAGE
  36. #    awk -f uucp.times.awk /usr/spool/uucp/LOGFILE
  37. #
  38. # Actually -- I would suggest saving LOGFILE somewhere and make
  39. # sure uucico is no longer writing to it.  This way you're sure
  40. # that the data generated is valid.  What I do here is:
  41. #
  42. #    set `date`
  43. #    tag=$2.$7
  44. #    cd /usr/spool/uucp
  45. #    mv LOGFILE OLD/LOGFILE.${tag}
  46. #    compress OLD/LOGFILE.${tag}
  47. #    uncompress OLD/LOGFILE.${tag}
  48. #    awk -f /usr/lib/uucp/uucp.times.awk OLD/LOGFILE.${tag}
  49. #
  50. # Somehow, compress waits until nobody is using the file before it
  51. # compresses it.  This is nice and convenient.
  52. #
  53. #
  54. # AUTHOR
  55. #    David Herron (NPR lover)
  56. #    cbosgd!ukma!david
  57. #    University of Kentucky, Computer Science
  58.  
  59. BEGIN    {
  60.     # states
  61.     idle = 0; calling = 1; uscall = 2; themcall = 3;
  62.     true = 1; false = 0
  63.  
  64.     # This ignores log entries for these systems.  They're
  65.     # all local calls so we don't care how much time we 
  66.     # spend talking to them.
  67.     ignore["ukgs"] = true
  68.     ignore["ukmb"] = true
  69.     ignore["ukmc"] = true
  70.     ignore["ukmd"] = true
  71.     ignore["ukme"] = true
  72.     ignore["ukmf"] = true
  73.     ignore["ma3b2a"] = true
  74.     ignore["ma3b2b"] = true
  75.     ignore["ukecc"] = true
  76.     ignore["ecc1"] = true
  77.     ignore["ukengr4"] = true
  78.     ignore["ukpa"] = true
  79.     ignore["mason"] = true
  80.     ignore["pcb"] = true
  81.     # This one only calls us ... and, we don't really
  82.     # care how much he spends ... That's his problem
  83.     ignore["hasmed"] = true
  84.     }
  85.  
  86. # We're calling some place, and the call part has actually worked.
  87. # 1) Record their name in the master list.
  88. # 2) Remember that we're placing the call.
  89.  
  90. $4 == "SUCCEEDED" && $5 == "(call" {
  91.     if (ignore[$2] != true)
  92.         state[$2] = calling
  93.     else
  94.         state[$2] = idle
  95.     }
  96.  
  97. # A call succeeded.  Either they called us or we called them.
  98. # state[$2] tells us who is doing the calling.
  99. # Have to remember the time.
  100.  
  101. $4 == "OK" && $5 == "(startup)" {
  102.     if (ignore[$2] != true) {
  103.         startime[$2] = $3
  104.         if (state[$2] == calling) {
  105.             printf("call\tout\t%s\t%s\n", $2, $3)
  106.             state[$2] = uscall
  107.         }
  108.         else {
  109.             printf("call\tin\t%s\t%s\n", $2, $3)
  110.             state[$2] = themcall
  111.         }
  112.     }
  113.     }
  114.  
  115. # Our outgoing call failed.  Throw away our information about the call.
  116.  
  117. $4 == "TIMEOUT" {
  118.     state[$2] = idle
  119.     }
  120.  
  121. # A call finished either successfully or unsuccessfully.
  122. # Have to add in the time to the appropriate sum.
  123. #
  124. # It would be "hard" to calculate the time correctly.  So, I'm using
  125. # a heuristic here to make it easy.  I assume that no phone call is
  126. # going to last for longer than 1 day.  I calculate the time
  127. # for the ending and beginning of the call, and if it's negative
  128. # I add 24 hours to it.
  129. #
  130. # I know ... groady to the max, buuut...
  131.  
  132. ($4 == "OK" || $4 == "FAILED") && $5 == "(conversation" {
  133.     if (ignore[$2] != true) {
  134.         printf("done\t(%s)\t%s\t%s\n", $4, $2, $3)
  135.         time = 0
  136.         # get time spent into "time"
  137.         # Time format is: "(mon/day-hr:min-pid)"
  138.         n = split($3, nn, "-")
  139.         n = split(nn[2], hrmin, ":")
  140.         tend = (hrmin[1]*60) + hrmin[2]
  141.         n = split(startime[$2], nn, "-")
  142.         n = split(nn[2], hrmin, ":")
  143.         tbeg = (hrmin[1]*60) + hrmin[2]
  144.  
  145.         time = tend - tbeg
  146.         if (time < 0)
  147.             time += (24*60)
  148.  
  149.         if (state[$2] == uscall)
  150.             ourtime[$2] += time
  151.         else
  152.             theirtime[$2] += time
  153.     }
  154.     }
  155.  
  156. # All that's left to do now is to feed the chickens and go home
  157.  
  158. END    {
  159.     for (i in ourtime)
  160.         printf("%s -- ourtime = %d\ttheirtime = %d\n", \
  161.             i, ourtime[i], theirtime[i])
  162.     }
  163.  
  164.