From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM"  2-JUN-1993 15:21:59.68
To:	EVERHART
CC:	
Subj:	Maintaining truth in time when booting VMS

X-Newsgroups: comp.os.vms
From: ghc@vger.niddk.nih.gov
Subject: Maintaining truth in time when booting VMS
Message-ID: <2JUN93.18581325@vger.niddk.nih.gov>
Sender: postman@alw.nih.gov (AMDS Postmaster)
Organization: NIH K-LMB, Molecular Structure
Date: Wed, 2 Jun 1993 23:58:13 GMT
Lines: 104
To: Info-VAX@KL.SRI.COM
X-Gateway-Source-Info: USENET

A short while ago our console (a PRO380) was updated and the clock
came up one year advanced.  The ramifications from this took us more
than a week to straignten out and I dreamed of a way to prevent this
nightmare.  I've come up with a procedure which will warn me that
something is awry and I hope that others may find the idea worthwhile. 
Near the beginning of the file SYSTARTUP_V5.COM, before any files are
touched, I scan a list of files that I know are touched during a
normal period of up-time.  If latest of the RDTs (revision date_time)
is within 30 days of what the system thinks is the current time, I
accept it.  I throw away any RDT which is too near the supposedly
current date_time on the presumption that the file may have just been
touched.  To implement in your location you will have to examine your
system for some files which meet the criteria I outlined above.

Gerson H Cohen
National Institutes of Health, 5/335
Bethesda, MD  20892
ghc@vger.niddk.nih.gov

***** DCL segment placed in SYSTARTUP.COM *****
$!
$!  Try to trap a bad clock
$!
$	BELL[0,8] = %X7
$	BAD == -1
$	@SYS$MANAGER:SCAN-FILE_DATES
$	IF BAD.EQ.1
$	  THEN
$	    WRITE SYS$OUTPUT bell,bell
$	    WRITE SYS$OUTPUT "The system clock is suspect.  If it is"
$	    WRITE SYS$OUTPUT "correct, answer YES to the following:"
$ CHECK:
$	    READ/PROMPT="Correct (Y/[N]) ? " SYS$COMMAND CORRECT
$	    IF .NOT.CORRECT
$	      THEN
$		READ/PROMPT="Enter the correct time [DD-MMM-YYYY:HH:MM] - " -
    			SYS$COMMAND NEW_TIME
$		SET TIME="''NEW_TIME'"
$		WRITE SYS$OUTPUT "** The time is supposedly ''F$TIME()'"
$	 	GOTO CHECK
$	      ENDIF
$	  ENDIF
$	WRITE SYS$OUTPUT "The time is OK"

***** @SYS$MANAGER:SCAN-FILE_DATES.COM *****

$!  This procedure scans a list of files which are modified during
$!  startup and periodically during uptime in order to determine a
$!  reasonable last time stamp which can be compared with the current
$!  time reading.  This is done in an attempt to trap the condition
$!  where the TOY clock comes up one year advanced and causes tons of
$!  problems.  Files having a RDT within 10 minutes of current are
$!  skipped on the suspicion that they may already have been touched
$!  in the current boot.
$!
$ bell[0,8] = %x7
$ file_list = "ACCTODATE.DAT/ACCOUNTNG.DAT/ANJECOUNT.LOG/ANJERECV.DAT" -
            + "/ANJESENT.DAT/ARGUS.LOG/EVL.LOG/IPLDATA.TXT/MOM.LOG" -
            + "/MONITOR.ERR/MONITOR.LOG/MOUNT_MVAD.LOG/MOUNT_MVGR.LOG" -
            + "/MOUNT_PCS.LOG/MOUNT_RAXIS.LOG/NETSERVER.LOG/OPERATOR.LOG" -
            + "/PLOTQMAN.OUT/REBUILD.LOG/SYANJE.LOG/WPCORP$STARTUP.LOG"
$ n = 0
$ c_time = f$cvtime("yesterday-500-0:0")
$ a_time = "yesterday-500-0:0"
$ a_file_found = 0
$next_file:
$ the_file = f$element(n,"/",file_list)
$ if the_file.nes."/"
$  then
$   if f$search(the_file).nes.""
$    then
$     when = f$file_attributes(the_file,"RDT")
$     write sys$output "The file ''the_file' last modified at ''when'"
$     if f$cvtime("").gts.f$cvtime("''when'+0-0:10") ! RDT within last 10 min?
$      then
$      new_time = f$cvtime(when)
$       if new_time.gts.c_time
$        then
$         c_time = new_time
$         a_time = when
$         a_file_found = 1
$        endif
$      endif
$    endif
$  else
$   write sys$output "The latest file RDT is ''a_time'"
$   write sys$output "Today is ''f$cvtime("","absolute")'"
$   plus_thirty = f$cvtime("''a_time'+30-0:0","absolute")
$   write sys$output "Thirty days beyond the latest RDT is ''plus_thirty'"
$   if a_file_found.eq.1 .and. f$cvtime("").lts.f$cvtime("''a_time'+30-0:0")
$    then
$     write sys$output "We may proceed"
$     bad == 0
$    else
$     write sys$output bell,bell
$     write sys$output "** Please check the clock before continuing. **
$     write sys$output "** The time is supposedly ''f$time()'"
$     bad == 1
$     exit
$    endif
$   exit
$  endif
$ n = n + 1
$ goto next_file

