home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / ertime12.zip / ERRTIME.DOC next >
Text File  |  1995-05-06  |  15KB  |  447 lines

  1.  
  2.                          ┌─────────────────────┐
  3.                          │ ErrTime version 1.2 │
  4.                          └─────────────────────┘
  5.  
  6. Released to public domain by Phil Money, PGM Consulting, 6 MAY 95
  7.  
  8. Many more errorlevels have been added to ErrTime since v1.0 and v1.1
  9.  
  10. There are seperate versions of ErrTime for DOS, OS/2, Windows-NT and Novell
  11. NetWare 386.  It was written and compiled in Watcom C++ v10.0a.
  12.  
  13. No warranty of any kind is offered.
  14.  
  15.     USAGE: ErrTime -h | -H | -d | -D | -w | -W | -m | -M | -s | -y
  16.  
  17.        Valid options are:
  18.                -h   Return Hour as an errorlevel 0-23
  19.                -H   Return Hour as an errorlevel 1-12
  20.                -d   Return Day of month as an errorlevel 1-31
  21.                -D   Return Day of week as an errorlevel 0-6 (Sunday is 0)
  22.                -w   Return Week as an errorlevel 0-52 starting Sunday
  23.                -W   Return Week as an errorlevel 0-52 starting Monday
  24.                -m   Return Month as an errorlevel 1-12
  25.                -m   Return Minute as an errorlevel 0-59
  26.                -m   Return Second as an errorlevel 0-59
  27.                -y   Return Year as an errorlevel 0-99
  28.  
  29.  
  30. ErrTime exits with errorlevel 255 if invalid arguments are given.
  31.  
  32. You can only enter one argument on the command line.  If more than one argument
  33. is given, ErrTime will use only the first argument.
  34.  
  35. This is a simple utility to assist scheduling events at specified times.
  36. ErrTime returns an errorlevel equal to the time of day hour in 24 hour or 12
  37. hour format, minute, second, day of month or day of week, week of year or month
  38. of year, or year of century.  For example, if it's 2am it will return an
  39. errorlevel of 2 or if it's 2pm (14:00) it will return an errorlevel of 14, etc.
  40. The error level can then be used by a batch, CMD or NCF file to execute the
  41. appropriate commands to run programs or just do nothing.
  42.  
  43. Of course, you can also schedule a block of time larger than just one hour, one
  44. day or one month or even combine them all by running ErrTime more than once.
  45. See the sample batch file below.
  46.  
  47. Errtime differs from some other errorlevel programs in that it doesn't evaluate
  48. anything or require any complex command line parameters.  It simply returns the
  49. errorlevel and lets your batch file do the rest.  This means you won't have to
  50. run ErrTime 24 times to test for the hour of the day, or 12 times for the month
  51. or 100 times for the year, etc.  You only need to run it once and let the batch
  52. file do the testing.  This is much more practical than running a program
  53. multiple times.  This might not be what your application needs though. If you
  54. need a program that does complex "what-if" calculations look elsewhere.
  55.  
  56. ErrTime writes nothing to your drive, opens no files, requires no input or
  57. changes anything about your computer except to return an errorlevel to the
  58. operating system after it checks the time and date and exits.  All programs
  59. return an errorlevel of some form.  ErrTime just returns them with the same
  60. number as the hour of the day, day of month or month of year etc.  Pretty
  61. simple stuff eh?  If you're not familiar with using errorlevels in batch,
  62. CMD or NCF files, read your manual.  One of the sample files should be
  63. enough to get you up and running even if you don't know anything about
  64. errorlevels.
  65.  
  66.  
  67. Note:
  68.  
  69. Batch files examine all errorlevels using a greater-than-or-equal-to operation.
  70. In other words, the statement 'If ErrorLevel 1 echo Happy new year!' will
  71. display the sentence 'Happy new year!' if the errorlevel was set to 1, but will
  72. ALSO display 'Happy new year!' if the errorlevel was set to 2, 3, or above.
  73. For this reason, if you have more than one errorlevel to check for, you should
  74. always arrange the group of errorlevel statements in a DESCENDING order.  For
  75. example, to check for errorlevels 0, 9 and 12, this would be the proper way to
  76. place the statements in your batch file:
  77.  
  78.                ErrTime -h
  79.  
  80.                If ErrorLevel 12 Email.Exe
  81.                If ErrorLevel  9 CashReg.Exe
  82.                If ErrorLevel  0 BackUp.Bat
  83.  
  84. One other point to remember is that ALL programs modify the DOS errorlevel.  In
  85. the example given above, if you were to run a program called ABC123.EXE for the
  86. 'If ErrorLevel 12' statement, ABC123 would RESET the DOS errorlevel after
  87. ABC123.EXE terminated.  Since the batch file is executed one line at a time,
  88. the errorlevel statements which follow would use the errorlevel set by the
  89. ABC123 program, rather than the value set by ErrTime.  To get around this DOS
  90. limitation, you must instead use a GOTO statement for the 'action' portion of
  91. the errorlevel statement.
  92.  
  93. The GOTO command allows your batch file to jump to a completely different
  94. location within the same batch file, and start executing commands from that
  95. point.  This is accomplished by using a statement in the form of 'GOTO <l>',
  96. where <l> is a LABEL.  A label is a unique, alphanumeric, ONE-WORD name, which
  97. indicates where in the batch file you wish to jump to.  Some valid labels could
  98. be called 'DoTape', 'Run_The_Cash_Register', and 'Shutdown'.  However, a GOTO
  99. statement alone is not enough to complete the GOTO operation.  You must also
  100. place the same label somewhere else within the batch file, which lets DOS know
  101. where the GOTO statement should end up.  You can do this simply by placing a
  102. colon (':') at the beginning of a line, simply followed by the label name.
  103.  
  104. For example, the following sample batch file:
  105.  
  106.           :Loop
  107.           echo This will be shown over and over
  108.           goto Loop
  109.  
  110. ...would cause the line 'This will be shown over and over' to continuously
  111. display on the screen, until the user hits control-C to abort.  When DOS starts
  112. the batch file, it will process each line in sequence.  When DOS reads line 1,
  113. it will recognize that 'Loop' is simply a label definition, and will ignore it.
  114. Next, DOS will read line 2, and process the ECHO command, by displaying
  115. 'This will be shown over and over' on the screen.  Once DOS encounters line 3,
  116. it will realize that it contains a GOTO statement, and look for the ':Loop'
  117. label, and jump back to line 1, continuing the cycle.
  118.  
  119. However, the GOTO command does have practical applications.  The above example
  120. could be re-written like this:
  121.  
  122.                ErrTime -h
  123.  
  124.                If ErrorLevel 12 Goto Email
  125.                If ErrorLevel  9 Goto CashReg
  126.                If ErrorLevel  0 Goto BackUp
  127.  
  128.  
  129.                :Email
  130.                REM * Run Email.
  131.                Email.Exe
  132.                goto End
  133.  
  134.                :CashReg
  135.                REM * Run CashReg.
  136.                CashReg.Exe
  137.                goto End
  138.  
  139.                :BackUp
  140.                REM * Run Tape Backup.
  141.                Backup.Bat
  142.                goto End
  143.  
  144.                :End
  145.  
  146.  
  147. In this situation, DOS would first compare the errorlevel returned by ErrTime
  148. to those listed in the 'If ErrorLevel' portion of the batch file, and then jump
  149. down to the corresponding label.
  150.  
  151. For example, if ErrTime exited using errorlevel 10, DOS would jump down to
  152. ':CashReg', and process the statements which followed.  The REM statement is
  153. simply a remark, and is ignored by DOS.  After skipping the REM command, DOS
  154. then reads the next line of the batch file, and processes it.  The 'goto End'
  155. statement is necessary, to make sure that DOS does not keep going, and execute
  156. the commands for 'BackUp' as well.  (Remember that DOS just ignores LABEL
  157. DEFINITIONS, such as ':BackUp'.  Without the extra 'goto End', the batch file
  158. would just 'fall through' to the statements under Email, Backup, etc.  The
  159. extra goto specifically instructs DOS to jump to the ':End' label, which is
  160. located at the end of the batch file.
  161.  
  162. Some times you may WANT the batch file to 'fall through', since it allows one
  163. to have several similar commands to be processed, when using the same
  164. errorlevel.
  165.  
  166. Arranging the batch file like this allows for more than one command to be
  167. executed for a certain errorlevel, and in addition, gets around the
  168. above-mentioned problem of other programs changing the errorlevel.
  169.  
  170. A generic batch or .cmd file for ErrTime might look something like this:
  171.  
  172. ------------------------------------------------------------------------------
  173.  
  174. @Echo Off
  175.  
  176. cd \Bink
  177.  Rem Check day of week
  178.  errtime2 -D
  179.    if errorlevel 1 goto monthday
  180.    Rem The above line catches any fall-through errorlevels above errorlevel 0
  181.    if errorlevel 0 goto sunday
  182.  goto monthday
  183.  
  184. :sunday
  185.  cd \max
  186. msgpostp -Te:\bink\weekly.Rpt -Cmpsqrwk.cfg
  187. if exist \bink\weekly.dat del \bink\weekly.dat
  188.  
  189. Rem The batch/CMD file automatically falls through to chkmonth after
  190. Rem sunday since no goto statment sends it anywhere else.
  191.  
  192. :monthday
  193. cd \Bink
  194.  Rem Check day of month
  195.  errtime2 -d
  196.    if errorlevel 2 goto daily
  197.    Rem The above line catches any fall-through errorlevels above errorlevel 1
  198.    if errorlevel 1 goto day1
  199.  goto daily
  200.  
  201. :day1
  202.  cd \max
  203.  msgpostp -T\bink\Monthly.Rpt -Cmpsqrmth.cfg
  204.  if exist \bink\monthly.dat del \bink\monthly.dat
  205.  cd \bink
  206.  call notify
  207.  cd \bink
  208.  Rem Check month
  209.  errtime2 -m
  210.    if errorlevel 2 goto daily
  211.    Rem The above line catches any fall-through errorlevels above errorlevel 1
  212.    if errorlevel 1 goto january1
  213.  goto daily
  214.  
  215. :january1
  216.  msgpostp -T\bink\Yearly.Rpt -Cmpsqryr.cfg
  217.  if exist \bink\yearly.dat del \bink\yearly.dat
  218.  
  219. :daily
  220.  cd \max
  221.  msgpostp -T\bink\daily.Rpt -Cmpsqrday.cfg
  222.  if exist \bink\daily.dat del \bink\daily.dat
  223.  
  224. :end
  225.  cd \bink
  226.  REM * Re-Run BinkleyTerm
  227.  Bink
  228.  
  229. ------------------------------------------------------------------------------
  230.  
  231. The included files are only examples of how one might use this program.
  232.  
  233. If you have any questions, comments or suggestions you can contact me at the
  234. following addresses:
  235.  
  236. philmoney@aol.com
  237. arscsm%91.malmstrom@lan.malmstrom.af.mil
  238. Phil Money at FidoNet 1:3400/37.1
  239.  
  240. or you can write to:
  241.  
  242. Phil Money
  243. PSC Box 11400
  244. Malmstrom AFB, MT USA 59402-5000
  245.  
  246.  
  247. More batch file examples follow:
  248. -----------------------------------------------------------------------------
  249. @echo off
  250.  
  251. REM An easy way to schedule an BBS door access and maintenance...
  252.  
  253. errtime -d
  254.  
  255. if errorlevel 2 goto daily
  256. Rem The above line catches any fall-through errorlevels above errorlevel 1
  257. if errorlevel 1 goto monthly
  258. goto daily
  259.  
  260. :monthly
  261. errtime -h
  262. if errorlevel 1 goto endbat
  263. Rem The above line catches any fall-through errorlevels above errorlevel 0
  264. if errorlevel 0 call purge.bat
  265.  
  266. :daily
  267. errtime -h
  268. if errorlevel 23 goto closed
  269. if errorlevel 22 goto open
  270. if errorlevel 21 goto closed
  271. if errorlevel 20 goto open
  272. if errorlevel 19 goto closed
  273. if errorlevel 18 goto closed
  274. if errorlevel 17 goto closed
  275. if errorlevel 16 goto open
  276. if errorlevel 15 goto closed
  277. if errorlevel 14 goto open
  278. if errorlevel 13 goto open
  279. if errorlevel 12 goto closed
  280. if errorlevel 11 goto closed
  281. if errorlevel 10 goto open
  282. if errorlevel 9 goto open
  283. if errorlevel 8 goto closed
  284. if errorlevel 7 goto closed
  285. if errorlevel 6 goto open
  286. if errorlevel 5 goto open
  287. if errorlevel 4 goto open
  288. if errorlevel 3 goto open
  289. if errorlevel 2 goto open
  290. if errorlevel 1 goto open
  291. if errorlevel 0 goto open
  292. goto endbat
  293.  
  294. :open
  295. c:
  296. cd \bbs\doors\mydoor
  297. mydoor.exe
  298. goto endbat
  299.  
  300. :closed
  301. display closed.bbs
  302.  
  303. :endbat
  304. c:
  305. cd \bbs
  306. call cleanup.bat
  307. bbs.bat
  308.  
  309. -----------------------------------------------------------------------------
  310. @echo off
  311.  
  312. REM A different program for every hour?...
  313.  
  314. errtime.exe -h
  315.  
  316. if errorlevel 23 goto hour23
  317. if errorlevel 22 goto hour22
  318. if errorlevel 21 goto hour21
  319. if errorlevel 20 goto hour20
  320. if errorlevel 19 goto hour19
  321. if errorlevel 18 goto hour18
  322. if errorlevel 17 goto hour17
  323. if errorlevel 16 goto hour16
  324. if errorlevel 15 goto hour15
  325. if errorlevel 14 goto hour14
  326. if errorlevel 13 goto hour13
  327. if errorlevel 12 goto hour12
  328. if errorlevel 11 goto hour11
  329. if errorlevel 10 goto hour10
  330. if errorlevel 9 goto hour9
  331. if errorlevel 8 goto hour8
  332. if errorlevel 7 goto hour7
  333. if errorlevel 6 goto hour6
  334. if errorlevel 5 goto hour5
  335. if errorlevel 4 goto hour4
  336. if errorlevel 3 goto hour3
  337. if errorlevel 2 goto hour2
  338. if errorlevel 1 goto hour1
  339. if errorlevel 0 goto hour0
  340. goto endbat
  341.  
  342. :hour23
  343.  REM put command here if you want it to run during this hour
  344.  goto endbat
  345.  
  346. :hour22
  347.  REM put command here if you want it to run during this hour
  348.  goto endbat
  349.  
  350. :hour21
  351.  REM put command here if you want it to run during this hour
  352.  goto endbat
  353.  
  354. :hour20
  355.  REM put command here if you want it to run during this hour
  356.  goto endbat
  357.  
  358. :hour19
  359.  REM put command here if you want it to run during this hour
  360.  goto endbat
  361.  
  362. :hour18
  363.  REM put command here if you want it to run during this hour
  364.  goto endbat
  365.  
  366. :hour17
  367.  REM put command here if you want it to run during this hour
  368.  goto endbat
  369.  
  370. :hour16
  371.  REM put command here if you want it to run during this hour
  372.  goto endbat
  373.  
  374. :hour15
  375.  REM put command here if you want it to run during this hour
  376.  goto endbat
  377.  
  378. :hour14
  379.  REM put command here if you want it to run during this hour
  380.  goto endbat
  381.  
  382. :hour13
  383.  REM put command here if you want it to run during this hour
  384.  goto endbat
  385.  
  386. :hour12
  387.  REM put command here if you want it to run during this hour
  388.  goto endbat
  389.  
  390. :hour11
  391.  REM put command here if you want it to run during this hour
  392.  goto endbat
  393.  
  394. :hour10
  395.  REM put command here if you want it to run during this hour
  396.  goto endbat
  397.  
  398. :hour9
  399.  REM put command here if you want it to run during this hour
  400.  goto endbat
  401.  
  402. :hour8
  403.  REM put command here if you want it to run during this hour
  404.  goto endbat
  405.  
  406. :hour7
  407.  REM put command here if you want it to run during this hour
  408.  goto endbat
  409.  
  410. :hour6
  411.  REM put command here if you want it to run during this hour
  412.  goto endbat
  413.  
  414. :hour5
  415.  REM put command here if you want it to run during this hour
  416.  goto endbat
  417.  
  418. :hour4
  419.  REM put command here if you want it to run during this hour
  420.  goto endbat
  421.  
  422. :hour3
  423.  REM put command here if you want it to run during this hour
  424.  goto endbat
  425.  
  426. :hour2
  427.  REM put command here if you want it to run during this hour
  428.  goto endbat
  429.  
  430. :hour1
  431.  REM put command here if you want it to run during this hour
  432.  goto endbat
  433.  
  434. :hour0
  435.  REM put command here if you want it to run during this hour
  436.  errtime -d
  437.  if errorlevel 1 call monthly.bat
  438.  
  439. :endbat
  440.  REM Put your cleanup routines here.
  441.  call daily.bat
  442.  echo.
  443.  echo Done!
  444.  echo.
  445.  
  446.  
  447.