home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / ftplog < prev    next >
Text File  |  2020-01-01  |  3KB  |  56 lines

  1. #!/usr/local/bin/kermit +
  2. #
  3. # f t p l o g
  4. #
  5. # Analyzes wuftpd-format log (including Kermit FTP-format transaction log).
  6. # Prints top 5 files and the number of times each was accessed.
  7. # Prints histogram of number of access vs number of files.
  8. # Each record contains blank-separated fields; the filename is the 9th field.
  9. #
  10. # Requires:    C-Kermit 7.0 Beta.08 or later.
  11. # Illustrates: Associative arrays, file i/o, word splitting, numeric sorting.
  12. #
  13. # An associative array, file<>, is built up of filenames and counts.
  14. # When complete, the file<> array is converted to 2 regular arrays, &a and &b.
  15. # &a and &b are sorted numerically by count in descending order.
  16. # The top 5 files are listed.
  17. # An associate array, hist<>, is created to build the histogram of counts.
  18. # The histogram is converted, sorted, and listed.
  19. #
  20. # Author: F. da Cruz, Columbia University, July 1999
  21.  
  22. local line name \%n \%m \%f            ; Local variables
  23. .default = /var/log/ftpd.log
  24. if eq "\v(osname)" "Linux" .default = /var/log/xferlog
  25. if def \%1 assign \%f \fcontents(\%1)
  26. if not def \%f asg \%f \m(default)     ; Name of log file
  27. fopen /read \%c \%f                    ; Open the log file
  28. if fail exit 1 Can't open \%f          ; Check
  29. echo Reading: \%f...                   ; Let use know what's happening
  30. while true {                           ; Loop through records
  31.     fread /line \%c line               ; Read a record
  32.     if fail break                      ; Check for EOF
  33.     increment \%m                      ; Count this record
  34.     .name := \fword(\m(line),9,{ })    ; Extract filename from this record
  35.     _increment file<\m(name)>          ; Count an access for this file
  36. }
  37. fclose \%c                             ; Close the file
  38. echo Records: \flpad(\%m,5)            ; Tell user how many records
  39. .\%n := \faaconvert(file,&a,&b)        ; Convert associative array to &a, &b
  40. echo Files:   \flpad(\%n,5)            ; Tell how many files
  41. echo
  42. echo Top 5 Files:
  43. array sort /reverse /numeric &b &a     ; Sort array &a and &b according to &b
  44. for \%i 1 \%n 1 {                      ; List top 5 files and build histogram
  45.     if ( <= \%i 5 ) echo { \%i. \&a[\%i]: \&b[\%i]}
  46.     _increment hist<\&b[\%i]>
  47. }
  48. echo
  49. echo { Hits Files}                     ; Print histogram heading
  50. .\%n := \faaconvert(hist,&a,&b)        ; Convert hist<> to &a and &b
  51. array sort /numeric &a &b              ; Sort &a and &b according to &a
  52. for \%i 1 \%n 1 {                      ; List each member
  53.     echo \flpad(\&a[\%i],5) \flpad(\&b[\%i],5)
  54. }
  55. exit 0
  56.