home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / cron.zip / cron.doc < prev   
Text File  |  1994-10-11  |  5KB  |  121 lines

  1. Simple but efficient and functional UNIX cron clone for OS/2
  2. ============================================================
  3.  
  4. This program got written in a hurry since the available cron clones
  5. for OS/2 didn't do what I needed: dispatch jobs in the background
  6. while running *invisibly* on my system.
  7.  
  8. What is cron?
  9. -------------
  10. Cron (the name is a UNIX relic) is a process that gets started when your
  11. machine boots and never stops until you shutdown again. During its life,
  12. it checks the contents of a certain disk file every minute (you can
  13. easily change the timing granularity to e.g. 5 minutes). If it finds
  14. that the current time and date are matched by an entry in the file,
  15. cron starts up the process also named in the file.
  16.  
  17. This sounds boring but in practice, cron is the most handy tool for
  18. repetitive background scheduling I ever encountered.
  19.  
  20.  
  21. Controlling cron: the crontab file
  22. ----------------------------------
  23. The CRONTAB file (UNIX relic again) contains the control lines for cron.
  24. Each line contains of six elements:
  25.  
  26. m h d m w command
  27.  
  28. The first five elements are time and date patterns. A star '*' here means
  29. "always fits". So, if you want to run a certain program each day at noon,
  30. you enter
  31.  
  32. 0 12 * * * command
  33.  
  34. in the CRONTAB file. This line means: "if cron detects that the current
  35. time and date equal zero minutes, 12 hours, any day-of-the-month, any
  36. month-of-the-year, and any day-of-the-week, it starts 'command'  ".
  37.  
  38. In the same way, you can specify e.g. a backup program that runs on
  39. Mondays at 01:00 hours:
  40.  
  41. 0 1 * * 1 command
  42.  
  43. (0 = Sunday, 1 = Monday etc.).
  44.  
  45. To be more flexible, cron also accepts multiple values. A simple driver
  46. for a cuckoo clock program would contain:
  47.  
  48. 0,30 * * * * command
  49.  
  50. to fire up 'command' at each full and half hour. Ranges are also possible;
  51. to have the cuckoo keep its mouth shut during the night, you enter:
  52.  
  53. 0,30 8-20 * * * command
  54.  
  55. and you can combine both individual values and ranges as in
  56.  
  57. 0,30 0,8-20 * * 1-5 command
  58.  
  59. Comments can also be entered into the CRONTAB file; just start them with a #
  60. (in fact, cron treats everything as a comment if it does not start with a
  61. number).
  62.  
  63.  
  64. Starting cron
  65. -------------
  66. Here the difficulty starts. The available crons for OS/2 had to be started
  67. in a session of their own, because of the way in which they started the 
  68. processes in the crontab file. Running a program in a session however:
  69.  
  70. A) Gives you an icon and an entry in the Window List;
  71. B) Asks you to close the window at system shutdown;
  72. C) Costs you more (memory) resources.
  73.  
  74. Especially B) and A) troubled me. I wanted cron to run completely invisible,
  75. and to die without making trouble. This is only possible if you detach a
  76. program under OS/2 instead of start it. Unfortunately, detached programs
  77. cannot 'start' other programs (DosStartSession) and the available crons
  78. did exactly this.
  79.  
  80. To start CRON, go to the directory where you keep your CRONTAB file and 
  81. type "detach cron". That's it. You get the PID of cron back and could use
  82. that for a KILL command later on. Running cron directly from a command 
  83. prompt by just typing "cron" works as well and now you can follow cron's
  84. output messages. Ctrl-C ends cron.
  85.  
  86. If you want cron to start up at each boot (the way it is intended to be
  87. run), be careful. You cannot just put cron into your CONFIG.SYS file
  88. (with a "run=" command), since cron uses some REXX functions that cannot
  89. be used if PM is not running. Don't ask me why; it just happened to be
  90. this way. So you either have to run cron from your STARTUP.CMD file
  91. or from your Startup folder. In STARTUP.CMD, just add "cd [crondirectory]"
  92. and "detach cron". In you Startup folder, create a Program Object or
  93. shadow CRON.CMD to do the same. Personally I prefer the STARTUP.CMD file.
  94.  
  95. You can log cron activities and errors by making use of the OS/2
  96. stdout and stderr redirection capabilities. Do something like
  97.  
  98. detach cron > cron.log 2> cron.err
  99.  
  100. and you get two files with usually meaningful output.
  101.  
  102.  
  103. General
  104. -------
  105. Cron was written in surprisingly few lines of REXX, OS/2's command script
  106. interpreter/compiler. Therefore the program is the source. You can
  107. modify everything you like. On my system, cron's activities are barely
  108. noticeable (one flick of the disk, no CPU spike on PULSE). 
  109. Instead of using SysSleep (a RexxUtil function) I could have used my
  110. self-written SLEEP program (five lines of C code) that would have
  111. enabled cron to be started from the CONFIG.SYS. I didn't because SLEEP
  112. is not part of any standard distribution and I wanted to be as general
  113. as possible.
  114.  
  115.  
  116.  
  117. Jeroen Hoppenbrouwers (hoppie@kub.nl)
  118. Infolab, Tilburg University
  119. The Netherlands
  120.  
  121.