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

  1. # Daily-Session-Log 
  2. #
  3. # Session log with automatic daily log file rotation.
  4. # Assumes a connection (of any kind) is already open,
  5. # e.g. to the control / logging port of a PBX, router, etc.
  6. # Note: in C-Kermit 8.0.211 you can use INPUT /NOMATCH rather
  7. # than specifying a "string that will never come".
  8. #
  9. # F. da Cruz, Columbia University, June 2004
  10. #
  11. # Parameters for this run, change as needed.
  12. # HINT: Use forward slash (/) in Windows pathnames.
  13.  
  14. .current := c:/logs/                      # Directory to run in
  15. .archive := c:/archive/                   # Directory to move old logs to
  16. set session-log text                      # Log in text mode or...
  17. set session-log timestamped-text          # Do this if you want timesamps added
  18. set input echo on                         # If you also want display on screen
  19.  
  20. # Local variables and macros
  21.  
  22. local logname                             # Name of log file
  23. local mode                                # Mode in which to open it
  24.  
  25. def ON_CTRLC if open session-log close session-log # Ctrl-C trap
  26. def ERRCHK if fail stop 1 "TROUBLE: \%1 - \v(errstring)" # Error handler
  27.  
  28. # Check directories and CD
  29.  
  30. if not directory \m(current) stop 1 "TROUBLE: \m(current) is not a directory"
  31. if not directory \m(archive) stop 1 "TROUBLE: \m(archive) is not a directory"
  32.  
  33. cd \m(current)                            # CD to desired directory
  34.  
  35. # Loop to open session log, log to it until just before midnight, then
  36. # close the log and move it to the archive directory.
  37.  
  38. while true {                              # Loop until interrupted
  39.     if open session-log close session-log # If a log is open close it
  40.     .logname := \v(ndate).log             # Get name for new log
  41.     .mode := new                          # Mode in which to open it
  42.     if exist \m(logname) .mode := append  # If file exists append to it
  43.     log session \m(logname) \m(mode)      # Open the log file
  44.     errchk "Open Log \m(logname)"
  45.     if eq \m(mode) new {                  # Heading only if new file
  46.         writeln session-log \v(day) \v(date) \v(time)
  47.     }
  48.     # Record everything that arrives until just before midnight.
  49.  
  50.     input 23:59:59 STRING_THAT_WILL_NEVER_COME
  51.     if success stop 1 "TROUBLE: Log \m(logname) terminated early"
  52.     if not open connection stop 1 "TROUBLE: Connection lost"
  53.  
  54.     # At midnight close the log and rotate it, taking care not to
  55.     # overwrite any existing files.  Assuming a reliable flow-controlled
  56.     # connection, no data will be lost during log rotation.
  57.  
  58.     close session-log
  59.     errchk "Close Log \m(logname)"
  60.     if not exist \m(archive)\m(logname) {
  61.         rename \m(logname) \m(archive)
  62.         errchk "Rename Log \m(logname) to \m(archive)"
  63.     }
  64.     sleep 2                               # Sleep until after midnight
  65. }
  66.