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

  1. #!/usr/local/bin/kermit +
  2. #
  3. # t i m e s t a m p
  4. #
  5. # A certain host has a syslogger on its Telnet port.  If you telnet
  6. # to it, you see syslog records scrolling by.  But the records do not
  7. # have timestamps.  This script makes a Telnet connection to the host
  8. # and displays the records with timestamps added.  It also appends the
  9. # timestamped records to a file.
  10. #
  11. # Requires: C-Kermit 7.0 or Kermit 95 1.1.18 or higher.
  12. #
  13. # Illustrates:
  14. #  . Reading lines of text from a communication connection.
  15. #  . Using local files.
  16. #  . How to "press any key" to interrupt a loop.
  17. #
  18. # Author: F. da Cruz, Columbia University, May 2000.
  19.  
  20. .host = syslog.xyzcorp.com               ; (*) Replace as needed
  21. .file = console.log                      ; (*) Remove if logfile not wanted.
  22.  
  23. set host \m(host)                        ; Try to make the connection
  24. if fail stop 1 Can't reach \m(host)
  25.  
  26. if def file {                            ; If logfile wanted
  27.     fopen /append \%c \m(file)           ; open it for appending
  28.     if fail stop 1 Can't open \m(file)
  29. }
  30. echo \v(date) \v(time): Begin log - Press any key to stop
  31.  
  32. set quiet on                ; Suppress informational messages
  33. set ask-timer 1             ; For sampling keyboard
  34. set input echo off          ; We'll handle input echoing ourselves
  35. set command interrupt off   ; Disable Ctrl-C
  36.  
  37. while true {                ; Loop to read each record
  38.     input -1 \13            ; (*) Replace with \10 if necessary
  39.     if fail break
  40.     .line :=  \v(date) \v(time): \ftrim(\v(input),\13\10)
  41.     echo \m(line)
  42.     if def file fwrite /line \%c \m(line)
  43.     clear input
  44.     getc \%x
  45.     if success break
  46. }
  47. ; Come here when a key has been pressed or the connection dropped.
  48.  
  49. echo \v(date) \v(time): Closing \m(host)...
  50. close connection
  51. echo \v(date) \v(time): Closing \m(file)...
  52. fclose \%c
  53. set command interrupt on
  54. set ask-timer 0
  55. end 0 \v(date) \v(time): Done, bye.
  56.