home *** CD-ROM | disk | FTP | other *** search
/ Big Blue Disk 51 / bbd51.zip / SCHEDULE.TXT < prev    next >
Text File  |  1990-11-13  |  14KB  |  361 lines

  1. |A╔═══════╦══════════════════════════════════════════════════════════════╦═══════╗
  2. |A║ ^0Tools |A║                          ^1 SCHEDULE |A                          ║^0 Tools|A ║
  3. |A╚═══════╩══════════════════════════════════════════════════════════════╩═══════╝
  4. ^Cby
  5. ^CMichael West
  6.  
  7.  
  8.  SCHEDULE is a batch-file utility that allows you to set up and run programs
  9.  and DOS commands based on a number of time factors.
  10.  
  11.  With SCHEDULE you can run programs and commands based on:
  12.  
  13.       The day of the week (Sunday, Wednesday etc.)
  14.       The day of the month
  15.       The day of the quarter
  16.       The specific day of the year (either in Gregorian or Julian format)
  17.       The number of elapsed days since the last time the commands were run
  18.  
  19.  ^1 Editor's note:  Since SCHEDULE is intended to be used in batch files, it is
  20.       ^1 not runnable from within the Big Blue Disk menu.  You may use this
  21.       ^1 utility from the DOS command-line or in batch files outside of BBD.
  22.  
  23.  
  24.  ^1Batch files^0
  25.  
  26.  Batch files are special files which contain lists of commands.  When you run a
  27.  batch file, each command in the list is executed just as if you had typed them
  28.  from the keyboard.  You can record all the steps necessary to perform some
  29.  common task in one batch file, then you will only have to remember the name of
  30.  this batch file rather than each individual step.  Batch files are valuable
  31.  tools for novices and experienced computer users.  For more information about
  32.  batch files, consult your MS-DOS reference manual.
  33.  
  34.  
  35.  ^1How SCHEDULE works^0
  36.  
  37.  Let's look at an example of how SCHEDULE can be used to make batch files even
  38.  more useful:
  39.  
  40.       SCHEDULE D 3/1
  41.       IF ERRORLEVEL 2 GOTO No_Backup
  42.  
  43.       ECHO Backing up files
  44.       BACKUP C:*.COM A: /s
  45.       GOTO End
  46.  
  47.       :No_Backup
  48.       ECHO No backup performed
  49.  
  50.       :END
  51.  
  52.  In this example we will backup all the files on drive C that have a COM
  53.  extension on March 1st.  SCHEDULE takes two operands (with one exception to be
  54.  discussed later).  The first operand, D in this case, tells SCHEDULE that the
  55.  second operand is a month and day.  When SCHEDULE runs it will check the date
  56.  in the computer and if it is NOT March 1st SCHEDULE will return ERRORLEVEL 2.
  57.  If the date IS March 1st, SCHEDULE returns an ERRORLEVEL 1.  You can use the
  58.  IF-ERRORLEVEL statement to bypass commands EXCEPT when the date you specify
  59.  occurs.
  60.  
  61.  Here's another example:
  62.  
  63.       SCHEDULE J 60
  64.       IF ERRORLEVEL 2 GOTO No_Backup
  65.  
  66.       ECHO Backing up files
  67.       BACKUP C:*.COM A: /s
  68.       GOTO End
  69.  
  70.       :No_Backup
  71.       ECHO No backup performed
  72.  
  73.       :End
  74.  
  75.  This is the same logic as the first example except that the first operand is a
  76.  J indicating that the second operand is a Julian date.  In this case we back
  77.  up all our COM files on the 60th day of the year (which is also March 1st
  78.  except in leap years).
  79.  
  80.  And that's all there is to it!  SCHEDULE returns only two error codes, 1 if
  81.  the date matches the date in the command line and 2 if it doesn't.
  82.  
  83.  Here is the complete list of SCHEDULE options:
  84.  
  85.       SCHEDULE D MM/DD - Checks the current month and day against the month and
  86.                          day in the second operand.
  87.  
  88.       Example: SCHEDULE D 9/14 - Returns ERRORLEVEL 1 on Sept. 14
  89.       else returns ERRORLEVEL 2.
  90.  
  91.  
  92.       SCHEDULE J NNN   - Checks the current Julian date against the Julian date
  93.                          in the second operand.
  94.  
  95.       Example: SCHEDULE J 100 - Returns ERRORLEVEL 1 on the 100th day of the
  96.       year (April 10), else returns ERRORLEVEL 2.
  97.  
  98.  
  99.       SCHEDULE M NN    - Checks the current day of the month against the one or
  100.                          two digit date specified in the second operand.
  101.  
  102.       Example: SCHEDULE M 9 - Returns ERRORLEVEL 1 if the current date is the
  103.       ninth day of the month (any month), else returns ERRORLEVEL 2.
  104.  
  105.  
  106.       SCHEDULE M L     - This option returns an ERRORLEVEL 1 if the current
  107.                          date is the last day of any month, otherwise it
  108.                          returns an ERRORLEVEL 2.  Using this option allows you
  109.                          to set up commands and programs that run at the end of
  110.                          the month without reciting to yourself "Thirty days
  111.                          hath September..."
  112.  
  113.  
  114.       SCHEDULE Q NN    - This option is similar to SCHEDULE M NN but it is
  115.                          based on the day of the quarter, instead of the month.
  116.                          This option allows you to run commands and programs on
  117.                          specific days within quarters.
  118.  
  119.       Example: SCHEDULE Q 10 - Returns ERRORLEVEL 1 if the current date is the
  120.       tenth day of any quarter (Jan. 10, Apr. 10, Jul. 10 or Oct. 10),
  121.       otherwise returns an ERRORLEVEL 2.
  122.  
  123.  
  124.       SCHEDULE Q L     - This option returns ERRORLEVEL 1 if the current date
  125.                          is the last day of any quarter (Mar. 31, Jun. 30,
  126.                          Sept. 30 or Dec. 31), otherwise it returns an
  127.                          ERRORLEVEL 2.  Using this option allows you to set
  128.                          up commands and programs that run at the end of each
  129.                          calendar quarter.
  130.  
  131.  
  132.       SCHEDULE W       - This option (Weekday) is used when you want to run
  133.                          commands or programs on a certain day of the week.
  134.                          Option 2 should be one of the following abbreviations:
  135.                          SUN, MON, TUE, WED, THU, FRI, SAT.
  136.  
  137.       Example: SCHEDULE W TUE - Returns ERRORLEVEL 1 if the current date is a
  138.       Tuesday, otherwise returns an ERRORLEVEL 2.
  139.  
  140.  
  141.  ^1Elapsed days option^0
  142.  
  143.  In addition to the above options it is also possible to SCHEDULE events based
  144.  on the number of elapsed days since the last time another event (or the same
  145.  one) was run.  Here's an example of how that works:
  146.  
  147.       SCHEDULE E201 14
  148.       IF ERRORLEVEL 2 GOTO End
  149.  
  150.       ECHO It's been fourteen days since we last ran CHKDSK
  151.       CHKDSK
  152.  
  153.       :End
  154.  
  155.  The first option is an elapsed day trigger.  SCHEDULE allows for 256 triggers
  156.  (E1 to E256).  In this case we have chosen to use trigger #201 (but we can use
  157.  any trigger we want for any purpose).  Elapsed day triggers are stored on a
  158.  special file (more about this later).
  159.  
  160.  The second operand (14) is the number of days in the elapsed period.  In this
  161.  case we run CHKDSK if 14 or more days have elapsed since the last time we ran
  162.  some batch file using trigger #201.
  163.  
  164.  To make the point a little clearer let's look at exactly what SCHEDULE does
  165.  when handling an elapsed day trigger.
  166.  
  167.       1.  SCHEDULE reads the trigger file.  In the above example, SCHEDULE
  168.           checks the date stored in trigger #201.
  169.  
  170.       2.  SCHEDULE adds the second operand (14 in our example) to the date in
  171.           the trigger.
  172.  
  173.       3.  If the new date is less than the current date SCHEDULE returns an
  174.           ERRORLEVEL 2.
  175.  
  176.       4.  If the new date is greater than, or equal to, the current date,
  177.           SCHEDULE returns an ERRORLEVEL 1 AND (THIS IS IMPORTANT!) updates the
  178.           trigger with the current date.
  179.  
  180.  So if our example were a batch file we run every day, CHKDSK would run when
  181.  fourteen or more days have elapsed since trigger #201 was set.  At that time
  182.  trigger #201 would be reset to the current date so that trigger would be
  183.  reactivated again fourteen days later.
  184.  
  185.  
  186.  ^1More on the triggers^0
  187.  
  188.  You have 256 triggers to work with.  Now you might think you need a lot of
  189.  triggers; for example if you used SCHEDULE three times in the same batch file,
  190.  or one time each in three different batch files you might think you need three
  191.  different triggers.  But if the number of elapsed days is the same, you can
  192.  use the same trigger repeatedly.  Here's an example of how to do it:
  193.  
  194.  SAVECOM.BAT contains the following code:
  195.       SCHEDULE E8 21
  196.       IF ERRORLEVEL 2 GOTO No_Backup
  197.  
  198.       BACKUP *.COM A: /s
  199.  
  200.       :No_Backup
  201.  
  202.  SAVEEXE.BAT contains the following code:
  203.       SCHEDULE E8 21
  204.       IF ERRORLEVEL 2 GOTO No_Backup
  205.  
  206.       BACKUP *.EXE A: /s
  207.  
  208.       :No_Backup
  209.  
  210.  The first example backs up all COM files every 21 days.  The second example
  211.  does the same thing for EXE files.  Both batch files use the same trigger (8).
  212.  But how can you do this?  Won't running the first example set trigger 8 every
  213.  21 days.  Wouldn't setting trigger 8 keep the second example from working
  214.  properly?
  215.  
  216.  No.  Here's why: THE CHANGE IN A TRIGGER'S DATE TAKES EFFECT ONLY AFTER YOU'VE
  217.  USED THAT TRIGGER FOR THE LAST TIME ON A GIVEN DATE.
  218.  
  219.  In the two examples above E8 would be set when the second file is run.  If a
  220.  third file uses and sets E8 THAT would be the point where the trigger is set.
  221.  
  222.  What this whole rigmarole means is that you can use a single trigger to
  223.  represent a series of elapsed days in more than one place.  You can use
  224.  trigger 3 to mean 3 elapsed days in many batch files (or more than one spot in
  225.  a single file).  You can use trigger 30 to represent 30 elapsed days (or 15,
  226.  or 92) throughout your system. The ability of a trigger to do double-duty
  227.  combined with 256 possible triggers gives you plenty to work with.
  228.  
  229.  You may of course wonder how SCHEDULE knows you've used a trigger for the last
  230.  time.  After all you may use it one time one day and five times on another.
  231.  Well the answer is rather technical and I won't bore you with it.  You'll just
  232.  have to trust me when I say that SCHEDULE knows when you've used a trigger for
  233.  the last time on a given date.
  234.  
  235.  
  236.  ^1Setting and viewing elapsed day triggers^0
  237.  
  238.  You can set an elapsed day trigger, either by specifying a specific date such
  239.  as Aug. 2, 1991 or by specifying a date relative to the current date.
  240.  
  241.       Example: SCHEDULE S118 9/14/90 - This sets trigger 118 to Sept. 14, 1990.
  242.  
  243.       Example: SCHEDULE S5 3/9/05 - This sets trigger to 5 to Mar. 9, 2005.
  244.  
  245.  
  246.  When setting a trigger the year must be a two digit number between 80 (1980)
  247.  and 79 (2079).  SCHEDULE makes the necessary adjustment.
  248.  
  249.  
  250.  You can also use a relative date adjustment:
  251.  
  252.       Example: SCHEDULE S61 * - This sets trigger 61 to the current date.
  253.  
  254.       Example: SCHEDULE S19 *+10 - Sets trigger 19 to the current date plus 10
  255.       days.
  256.  
  257.       Example: SCHEDULE S110-365 - Sets trigger 110 to the current date minus
  258.       one year.
  259.  
  260.  
  261.  You can set triggers in batch files or at the DOS prompt.  Setting triggers in
  262.  batch files allows you some flexibility in running your programs.  For example
  263.  here's a batch file I run at home every night before hitting the off switch
  264.  (SHUTDOWN.BAT).
  265.  
  266.       ECHO OFF
  267.       SCHEDULE E2 90
  268.       IF ERRORLEVEL 2 GOTO End
  269.  
  270.       ASK "Run Spinrite? " yn
  271.       IF ERRORLEVEL 2 GOTO Reset
  272.  
  273.       SPINRITE BATCH BLANKING AUTOEXIT AUTOREPORT
  274.       GOTO End
  275.  
  276.       :Reset
  277.       SCHEDULE E2 *-90
  278.  
  279.       :End
  280.       PARK
  281.  
  282.  Every 90 days I'm prompted to run Spinrite.  If I run Spinrite trigger #2 is
  283.  left set to the current date.  If I don't run Spinrite I branch to Reset and
  284.  set trigger 2 down by 90 days.  This causes SHUTDOWN.BAT to prompt me again
  285.  the following day.  As soon as I do run Spinrite SHUTDOWN.BAT quits pestering
  286.  me for another 3 months.
  287.  
  288.  Finally, you can view the date in a specific trigger by specifying the trigger
  289.  number alone:
  290.  
  291.       Example: SCHEDULE S28 - Displays the date currently stored in trigger 28.
  292.       The earliest possible date is 1/1/80.
  293.  
  294.  
  295.  ^1The trigger file^0
  296.  
  297.  The elapsed date trigger file is SCHEDULE.TRG.  It is created the first time a
  298.  trigger is used (either accessed, set or displayed).  SCHEDULE searches for
  299.  SCHEDULE.TRG by using the following steps:
  300.  
  301.       1. SCHEDULE searches the current directory.
  302.  
  303.       2. If SCHEDULE.TRG isn't found in the current directory
  304.          SCHEDULE searches each directory in the path.
  305.  
  306.       3. If SCHEDULE.TRG isn't found in the path then the file
  307.          is created in the current directory.
  308.  
  309.  When you first install SCHEDULE change to a directory that is in your path and
  310.  type SCHEDULE S1.  This will force SCHEDULE to create the trigger file where
  311.  SCHEDULE can always find it.
  312.  
  313.  When SCHEDULE.TRG is first created, all dates will be initialized to 1/1/80.
  314.  
  315.  
  316.  ^1Some final notes^0
  317.  
  318.  Errors:  If SCHEDULE detects an error, it will return an ERRORLEVEL 2 for all
  319.           operations except when setting a date.  Setting a date (the S
  320.           operation) always returns an ERRORLEVEL 0.
  321.  
  322.           Returning an ERRORLEVEL 2 means that commands won't be executed
  323.           because of an error.
  324.  
  325.  Case:    Despite the examples above SCHEDULE is not case sensitive.
  326.  
  327.  
  328.  ^1A final example^0
  329.  
  330.  This last example shows how you can use SCHEDULE to run GOAL TENDER every day
  331.  when you first start your computer:
  332.  
  333.       ECHO OFF
  334.  
  335.       REM Check trigger #5 to see if this is the first startup of the day.
  336.       REM If this is the first startup then display a random goal.
  337.       SCHEDULE E5 1
  338.       IF ERRORLEVEL 2 GOTO END_BATCH
  339.  
  340.       GOAL -R -F SAMPLE
  341.       REM Set trigger 5 to today so that only one goal will be displayed a day.
  342.       SCHEDULE S5 * >NUL
  343.  
  344.       :END_BATCH
  345.  
  346.  This file is included on the disk as RUNGOAL.BAT.  You may either add these
  347.  lines to the end of your AUTOEXEC.BAT file, or execute RUNGOAL as the last
  348.  line of your AUTOEXEC.BAT file.  In either case, you may change the trigger
  349.  number to any of the 256 triggers available.
  350.  
  351.  Use a standard text editor or the CATT utility to append this example to your
  352.  AUTOEXEC.BAT file.  Always make a backup copy of your AUTOEXEC.BAT file before
  353.  making any changes!
  354.  
  355.  
  356.  ^1Outside BBD^0
  357.  
  358.     To run this program outside ^1Big Blue Disk^0, type:  ^1SCHEDULE^0.
  359.  
  360.  DISK FILES THIS PROGRAM USES:
  361. ^FSCHEDULE.EXE