;ScheduledCapture.WAS     v1.0

;*****************************************************************************
;*                                                                           *
;* ScheduledCapture.WAS                                                      *
;* Copyright (C) 1998 Symantec                                               *
;* All rights reserved.                                                      *
;*                                                                           *
;* Written by:  Symantec ASPECT Assist                                       *
;* 04/02/98                                                                  *
;*                                                                           *                                                                             
;* This script file captures data at a scheduled time, saves it to a file,   *
;* and copies it to a specified location in MMDDYY.CAP format. It uses       *
;* whatever is the current connection as defined in setup.                   *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************


;****************************************************************************
;* Define Statements                                                        *
;****************************************************************************
#Define szPrimaryDirectory "f:\home\phonrpts\" ;Set the Primary directory.
#Define szBackupDirectory  "c:\backup\"        ;Set the Backup directory.
#define szTempCapDir       "c:\temp\"          ;Set the Temp directory.
#define szTempCapName      "temp.cap"          ;Set name for temporary CAP file
#Define szStartTime "23:50:00"                 ;24hr format.
#Define szEndTime   "01:30:00"


;****************************************************************************
;* Main Procedure                                                           *
;****************************************************************************
proc main
 
   while 1                               ;Loop forever.
      yield                              ;Yield processing time back to CPU.
      if stricmp $time24 szStartTime     ;Wait for time to start capture.
         CaptureData()                   ;Go to capture subroutine.
         yield                           ;Yield processing time back to CPU.
         pause 1
         MoveData()                      ;Go to the Move file routine.
      endif
   endwhile
endproc


;****************************************************************************
;* CaptureData                                                              *
;* This procedure captures the data from the current connection             *
;****************************************************************************
proc CaptureData

   set capture path szTempCapDir         ;Set the capture path.
   set capture file szTempCapName        ;Set the capture file name.
   
   set capture overwrite on              ;This can be set to append as well.
					 ;Simply set this to OFF
					 
   capture on                            ;Begin the capture.
   
   while 1				 ;Loop while capturing data.
      if stricmp $time24 szEndTime       ;Wait for time to end capture.
         capture off                     ;Turn off the capture.
         exitwhile                       ;Return to main procedure.
      endif 
   endwhile  
endproc


;****************************************************************************
;* MoveData                                                                 *
;* This procedure copies the captured data to the specified directory.      *
;****************************************************************************
proc MoveData

   string szRepDate, szTodaysDate, szTimeString, szThisYear, szThisMonth
   string szThisDay, szDestPrimary, szDestBackup
   string szTempFile = szTempCapDir
 
   strcat szTempFile "temp.cap"
   
   ltimestrs $ltime szTodaysDate szTimeString   ;Convert date to xx/xx/xx
   strextract szThisMonth szTodaysDate "/" 0    ;Extract the month for the name.
   strextract szThisDay   szTodaysDate "/" 1    ;Extract the day for the name.
   strextract szThisYear  szTodaysDate "/" 2    ;Extract the year for the name.

   strfmt szThisMonth "%02.2s" szThisMonth	;Format the Month part of name.
   strfmt szThisDay   "%02.2s" szThisDay        ;Format the Day part of name.
   
   strfmt szRepDate "%s%s%s.cap" szThisMonth szThisDay szThisYear 
   
                                                 ;Set the capture file name
                                                 ;Using MMDDYY.CAP format
      
   strfmt szDestPrimary "%s%s" szPrimaryDirectory szRepDate
   strfmt szDestBackup "%s%s" szBackupDirectory szRepDate

   if copyfile szTempFile szDestPrimary   ;Copy the report to primary location.
   else
      copyfile szTempFile szDestBackup    ;Copy the file to backup location if.
   					  ;the primary is not available.
   endif
endproc