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

  1. # l o g r o t a t e
  2. #
  3. # C-Kermit 7.0 includes a connection log feature.  If you enable it by
  4. # putting a LOG CONNECTIONS command in your C-Kermit startup file, each
  5. # new connection is appended to the log.  Therefore your connection log
  6. # file just grows and grows.  This script (if included in your C-Kermit
  7. # startup file) automatically starts a new log at the beginning of each
  8. # month, and keeps 4 months' worth of logs, discarding older ones.
  9. #
  10. # It works by comparing the yyyymm portion of the modification date
  11. # (\fdate()) of the given file (\%1) with the current yyyymm.  If they
  12. # differ, the current file has the yyyymm suffix (from its most recent
  13. # modification date) appended to its name.  Then we search through all
  14. # other such files, find the oldest one, and delete it.  Thus the current
  15. # log, plus the logs from the most recent four months, are kept.  This is
  16. # all done automatically every time you start C-Kermit.
  17. #
  18. define LOGROTATE {                    ; Define LOGROTATE macro
  19.     local \%i \%m \%d \%n \%f MAX
  20.     def MAX 4                         ; How many months to keep
  21.     if not def \%1 -                  ; No argument given
  22.       end 1 \%0: No filename given
  23.     if  < 1 \ffiles(\%1) -            ; Exactly 1 file must match
  24.       end 1 \%0: "\%1" - File not found
  25.     if > 1 \ffiles(\%1) -
  26.       end 1 \%0: "\%1" - Too many files match
  27.     .\%d := \fsubstr(\fdate(\%1),1,6) ; Arg OK - get file year & month
  28.     if = \%d -                        ; Compare file year & month
  29.       \fsubstr(\v(ndate),1,6) -       ; with current year & month
  30.     end 0                         ; Same year & month - done
  31.     rename \%1 \%1.\%d                ; Different - rename file
  32.     .\%n := \ffiles(\%1.*)            ; How many old files
  33.     if < \%n \m(MAX) end 0            ; Not enough to rotate
  34.     .\%m := \%1.999999                ; Initial compare string
  35.     for \%i 1 \%n 1 {                 ; Loop thru old logs
  36.        .\%f := \fnextfile()           ; Get next file name
  37.        if llt \%f \%m .\%m := \%f     ; If this one older remember it
  38.     }
  39.     delete \%m                        ; Delete the oldest one
  40. }
  41. log connections                       ; Now open the (possibly new) log
  42. logrotate \v(home)CX.LOG              ; Run the LOGROTATE macro
  43.