nbssetclk.ep 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # CHK=0x1C17
  2. #+---------------------------------------------------------------
  3. # nbssetclk - use NBSsetclk to set system time
  4. #
  5. # Place this directory entry in your /.ecu/phone file
  6. # and edit as necessary:
  7. #
  8. # .--[ entry: nbssetclk ]---------------------------------.
  9. # | |
  10. # | telephone number 1(202)653-0351 |
  11. # | device Any |
  12. # | bit rate 1200 |
  13. # | parity N |
  14. # | description Naval Observatory Time |
  15. # | debug level 0 (dialer -x value 0-9) |
  16. # | DCD watch n |
  17. # | RTS/CTS flow ctl n (0=off,7=best,n=no change) |
  18. # | |
  19. # | Enter telephone number |
  20. # | ESC: exit END: accept ^U: erase ^B: back TAB: fwd |
  21. # `-------------------------------------------------------'
  22. #
  23. # Run some command like this out of root crontab:
  24. # 30 3 * * 5 /usr/local/bin/ecu -p nbssetclk -D
  25. # which directs this script to run on Friday mornings at 3AM.
  26. # (If you use this, PLEASE CHOOSE A TIME TO CALL OTHER
  27. # THAN SHOWN IN THE EXAMPLE; I'd hate to be responsible for
  28. # a big spike in usage at some given minute. :> )
  29. #
  30. # The script makes $i_retries attempts to connect to NBS DC,
  31. # waiting $i_wait secs between each retry. Upon successful
  32. # connection,
  33. #
  34. # 1. NBSsetclk is invoked to get the time from NBS and set
  35. # the clock.
  36. #
  37. # 2. If tts can be found at the path in $s_tts, then my
  38. # TTS ("Tucker Time System") protocol hack broadcasts the
  39. # new time of day to all listeners on the attached subnet.
  40. #
  41. # 3. If usemorse can be found at the path in $s_morse,
  42. # my morse driver announces successful time capture.
  43. #
  44. #----------------------------------------------------------------
  45. #+:EDITS:
  46. #:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00
  47. #:09-15-1996-06:04-wht@n4hgf-clean up for 4.00
  48. #:09-13-1992-01:26-wht@n4hgf-creation
  49. # early reinforcement for interactive users
  50. echo 'Call NBS: ecu pid is '+%itos(%pid)
  51. # configuration
  52. $i_retries=10 # allow this many retries
  53. $i_wait=7 # seconds between retries
  54. $s_tts = '/etc/tts' # path to tts
  55. $s_morse = '/usr/local/bin/usemorse' # path to usemorse
  56. # make several attempts to connect
  57. $i_try = 1 # first attempt
  58. $i0 = 1 # make loop below run 1st time
  59. whilei $i0 != 0
  60. {
  61. echo '--> Dialing attempt '+%itos($i_try)
  62. dial 'nbssetclk' # make the call
  63. # be nice to an interactive user (allow loop abort)
  64. ifi $i0 == 2 # dial result of 2 says keyboard interrupt
  65. echo 'SIGINT: calling aborted'; goto SORRY
  66. # if the call fails otherwise, maybe retry
  67. ifi $i0 != 0
  68. {
  69. $i_try=$i_try+1
  70. ifi $i_try > $i_retries
  71. echo '--> Retries exhausted'; goto SORRY
  72. echo '--> Waiting '+%itos($i_wait)+' seconds ... '
  73. nap -m $i_wait*1000
  74. echo '\n'
  75. }
  76. # dial returned $i0==0, indicating success
  77. }
  78. echo '--> Connected to NBS'
  79. # update the time of day and the CMOS RAM from NBS-supplied time
  80. # (NBSsetclk -f switch gets the UNIX file descriptor of our NBS line,
  81. # reads the time from NBS and sets the clock with stime())
  82. $s10 = '/etc/NBSsetclk -f '+%itos(%conn)
  83. gosub EXEC_S10 # execute the command with sexy verbosity
  84. hangup # hangup immediately to save $$$
  85. # my time protocol hack has a special "one-time master" option
  86. # to spray the time of day all over the local subnet
  87. ifnz %isreg($s_tts) # if the program exists
  88. {
  89. $s10 = $s_tts+' -o -m -vvv'
  90. gosub EXEC_S10
  91. }
  92. # my morse driver announces success to anyone in the shack
  93. ifnz %isreg($s_morse) # if the program exists
  94. {
  95. $s10 = $s_morse+' -f 880 -t 5 nbs' # 880Hz, .05 sec/baud
  96. gosub EXEC_S10
  97. }
  98. echo '--> SUCCESS!'
  99. return # job well done ..............................
  100. # error bailout
  101. SORRY
  102. echo 'Sorry ... time capture failed '
  103. return 1 # non-zero return terminates any chain of proc executions
  104. #---------------------------------------------------------------------
  105. # subroutine to execute a shell command with verbosity
  106. EXEC_S10
  107. echo '--> '+$s10
  108. system -s $s10
  109. echo ''
  110. return # from subroutine