

NOVELL TECHNICAL INFORMATION DOCUMENT

TITLE:  BATCH PROGRAMMING
DOCUMENT ID:  TID800018
DOCUMENT REVISION:  A
DATE:  15AUG94
ALERT STATUS:  Yellow
README FOR:  NA

NOVELL PRODUCT and VERSION:
DR DOS 6.0

ABSTRACT:
NA

-----------------------------------------------------------------
DISCLAIMER
THE ORIGIN OF THIS INFORMATION MAY BE INTERNAL OR EXTERNAL TO NOVELL. 
NOVELL MAKES EVERY EFFORT WITHIN ITS MEANS TO VERIFY THIS INFORMATION. 
HOWEVER, THE INFORMATION PROVIDED IN THIS DOCUMENT IS FOR YOUR INFORMATION
ONLY.  NOVELL MAKES NO EXPLICIT OR IMPLIED CLAIMS TO THE VALIDITY OF THIS
INFORMATION.
-----------------------------------------------------------------

SYMPTOM

WRITING A BATCH PROGRAM THAT CAN EXECUTE MULTIPLE TIMES & PERFORM IT'S
DEFINED TASK ONLY ONCE

ISSUE/PROBLEM

Batch programming capabilities were recently changed.  These changes
became effective with COMMAND.COM files dated after 4/7/92.  The latest
COMMAND.COM is available via CompuServe or the Novell DSG Host BBS at
801-429-7785 for 300-2400 baud or 801-429-7787 for 9600 baud.

SOLUTION

This document contains a sample batch file that makes use of the changes
contained in the updated COMMAND.COM.  This sample file demonstrates the
creation of a batch program that can be executed a number of times but
will perform the defined task only once a day.

1. Create a file called DTFRCMP.TXT that contains the current date
information by typing the following from the command line:

     C:\>DATE >DTFRCMP.TXT

   Press the Enter key twice to be returned to the prompt.

2. Create a file called CR using the EDITOR (EDITOR.EXE).  This file will
contain a carriage return. To create this file:

   a. Type EDITOR CR at the command prompt
   b. When prompted, "do you wish to create a new file?"
      Type Y.
   c. You will then be in the EDITOR.  Enter a carriage return
      by pressing the ENTER key once.
   d. Save the file by holding the CTRL key down and then
      typing KX.

3. Create the main batch file that performs the daily routine.

   a. From the command prompt (C:\>) type: EDITOR TEST.BAT
   b. When prompted, "do you wish to create a new file?"
      Type Y.
   c. Proceed to type the following lines (creating the file):

@ECHO OFF
REM This logs the date information into a file.
DATE <CR >INF.TXT
REM This compares the preexisting date information
REM with the date information that was just created.
REM It creates a file with this information.
COMP INF.TXT DTFRCMP.TXT >CMP.RZT

REM This looks for the word "failure" in the created
REM text file. (This would be an indication that the
REM files are the same if "failure" was not found)...
REM Thus telling us that this batch file has already
REM been run today.
REM It pipes the results into a file.
FIND "FAILURE" CMP.RZT >DECIDER.TXT

REM If "failure" was found, then the file that was
REM created will have a file size.  If it was not
REM found then it will have a zero byte file size.
REM This will try to copy the file to another file.
REM If the original file is a zero byte file then
REM this procedure will fail because the COPY
REM command cannot copy a zero byte file.
COPY DECIDER.TXT FINAL.TXT >NUL

REM This checks to see if the final file was created.
REM If it was not, then the daily routine will be
REM bypassed...this batch file has already been run today.
IF NOT EXIST FINAL.TXT GOTO FINAL

REM If this section has been reached, then the batch
REM file has not been run today and it is going to
REM execute the once-a-day command that it is intended
REM to execute. This can be any command of your choosing
REM as long as it works from the DOS prompt.  The one that
REM has been chosen here is a command that copies the
REM config.sys file to a filename called ITWORKED.SYS.
:COPY
COPY C:\CONFIG.SYS C:\ITWORKED.SYS >NUL
ECHO Executing once-a-day routine...
REM This creates a new date-comparison file so that the
REM next time that this batch file is run it will see
REM that it has already been run today.

COPY INF.TXT DTFRCMP.TXT >NUL

REM This deletes the final comparison file that was created
REM today.
DEL FINAL.TXT

REM This cleans up all of the extra files and exits.
:END
DEL INF.TXT
DEL CMP.RZT
DEL DECIDER.TXT
EXIT

REM This tells you that it has already been run today.
:FINAL
echo Daily routine has already been run today.
GOTO END

If TEST.BAT is executed many times daily, it will create the file
ITWORKED.SYS just once a day.

NOTE: If you attempt to run this batch file on the same day that it was
created a message will be returned that this routine has already been run
today.  This is because the information in the DTFRCMP.TXT file is the
same as the current day's date.  If you wish to test it on the same day
that the file was created, you will have to change the date using the date
command.

This file can be incorporated in the AUTOEXEC.BAT file to execute every
time the computer is turned on.  To do this, use the EDITOR and add the
following line just before the line :DRDOSEND:

CALL TEST.BAT

Some possible uses of such a batch file would be running a daily virus
scan, system diagnostics or the disk optimizer.

-----------------------------------------------------------------
Any trademarks referenced in this document are the property of their
respective owners.  Consult your product manuals for complete trademark
information.
-----------------------------------------------------------------
