home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 274.lha / NazCron_v1.0 / NazCron.doc < prev    next >
Text File  |  1989-08-06  |  25KB  |  592 lines

  1. #1zz
  2.  
  3.  
  4.  
  5.  
  6.  
  7.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 1
  8.  
  9.  
  10.  
  11.  
  12.      Overview
  13.      --------
  14.  
  15.           NazCron executes CLI commands and programs that can be started
  16.           from a CLI at those times you specify in an event list.  This
  17.           event list is a memory resident list that can be loaded from the
  18.           file named CRONTAB located in the S: directory and/or from ARexx
  19.           scripts.  Every minute, NazCron examines the file timestamp.  If
  20.           it has changed in the last minute it reloads the event list from
  21.           the CRONTAB file.  NazCron then searches the event list for all
  22.           commands that need to be executed, executes each such command and
  23.           then issues a timer request to be re-activated a minute later.
  24.  
  25.           NazCron accepts the Unix Cron file format (see below) with minor
  26.           improvements, establishes itself as an ARexx host process and
  27.           operates in the background by disconnecting itself from the
  28.           initiating CLI.  A number of functions are controlled through the
  29.           ARexx interface asynchronously to event timing, i.e all such
  30.           functions are executed as soon as the initiating ARexx command
  31.           message is retrieved from the public message port. 
  32.  
  33.           NazCron is a redesign and rewrite of an Amiga public domain
  34.           program called AmiCron which, in turn, is an Amiga version of the
  35.           Unix program Cron.
  36.  
  37.  
  38.      Written by 
  39.      ---------- 
  40.  
  41.           Don Nafis 
  42.  
  43.           NazCron may be copied and freely distributed for personal use.
  44.  
  45.           NazCron is shareware, user-supported software.  If you like
  46.           NazCron and continue to use it after a trial period, please send
  47.           the $10 shareware fee to the address listed on the following page
  48.           and become a registered user.  As a registered user, you will be
  49.           assured of timely information on upgrades, you will be given
  50.           membership in the support section of our BBS, Viva! Amiga!, and
  51.           you will feel good about contributing to the development of new
  52.           utility programs for the Amiga.  By supporting all shareware
  53.           authors, you will be in the driver's seat when it comes to
  54.           deciding where future Amiga programs will be going; you will have
  55.           a loud voice when we programmers are trying to hear what Amiga
  56.           owners want in programs of the future. 
  57.  
  58.  
  59.  
  60.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  61. z
  62.  
  63.  
  64.  
  65.  
  66.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 2
  67.  
  68.           Send your check for $10.00 to
  69.  
  70.                Don Nafis
  71.                Nazlo Associates Ltd.
  72.                P.O. Box 1515
  73.                Laurel Springs, NJ  08021
  74.  
  75.           Please make your check payable to "Nazlo Associates Ltd.".
  76.  
  77.           Commercial vendors may distribute NazCron with their products as
  78.           long as they distribute all files provided here and make it clear
  79.           that NazCron is shareware.  Before distributing NazCron with your
  80.           package, you must send for written permission.  This way I can
  81.           make sure that you will be distributing the latest version.
  82.  
  83.           If you find this program lacking in any way and thus choose not
  84.           to register, I would like to hear your suggestions or complaints. 
  85.           Please contact me at one of the following and give me a piece of
  86.           your mind:
  87.  
  88.                Nazlo Associates Ltd.
  89.                P.O. Box 1515
  90.                Laurel Springs, NJ  08021
  91.  
  92.                (609) 228-8088 Voice
  93.  
  94.                (609) 227-8278 BBS -
  95.                                Viva! Amiga!
  96.                          3/12/24 - 8/N/1 - 24 hours
  97.                             130 Megabytes Online
  98.  
  99.                Compuserve 70656, 133
  100.  
  101.  
  102.      Usage
  103.      -----
  104.  
  105.           From the CLI, type:
  106.  
  107.                NazCron<cr>
  108.  
  109.           NazCron detaches itself from the initiating CLI as soon as it
  110.           begins execution.  Thus you can terminate the CLI, endcli, and
  111.           let NazCron go on working in the background. 
  112.  
  113.           From the Workbench:
  114.  
  115.                Place the pointer on the NazCron Icon and double click with
  116.                the left mouse button.
  117.  
  118.  
  119.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  120. z
  121.  
  122.  
  123.  
  124.  
  125.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 3
  126.  
  127.       
  128.           You will see no evidence that NazCron has begun executing in
  129.           either case unless you have a command in your CRONTAB that sends
  130.           a message to the console.  Should you panic and start NazCron
  131.           again, either from the CLI or Workbench, NazCron will detect that
  132.           there is a version already started and retire gracefully with no
  133.           harm done.  
  134.  
  135.           NazCron begins execution by loading the event list from the file
  136.           CRONTAB located in the S: directory.  (See below for the CRONTAB
  137.           file format.)  If CRONTAB is not present, NazCron simply waits
  138.           for further instruction through its ARexx port.  Since NazCron
  139.           doesn't need ARexx to run, it makes no attempt to determine if
  140.           ARexx is installed on the system.  Therefore you need not start
  141.           REXXMAST before you start NazCron.  If you have neither a CRONTAB
  142.           file in the S: directory nor ARexx, you will simply waste memory
  143.           by starting the program because you will be handling no events
  144.           and you have no way of terminating NazCron.
  145.  
  146.           Note that in order to detach itself completely from the
  147.           initiating CLI, NazCron must open a zero length file named
  148.           "ram:*".  This is a kludge to get around a quirk in "nil:" file
  149.           handling in the Execute() function of AmigaDos (no relation to
  150.           the AmigaDOS Execute command in the C: directory).  This file
  151.           will do no harm and, after terminating NazCron, you may delete
  152.           the it with no ill effects.
  153.  
  154.  
  155.      CRONTAB event format
  156.      --------------------
  157.  
  158.           The CRONTAB file is an ASCII text file which you must create with
  159.           a text editor and place in the S: directory.  Each entry in the
  160.           CRONTAB file is either a comment or a  event.  Each entry must
  161.           begin in column 1 with the individual parameters separated by
  162.           "white space", i.e. one or more spaces or tabs.
  163.  
  164.           The entry format is:
  165.  
  166.                ; comment
  167.                  - or -
  168.                [eventname] min hour day month weekday eventcommand
  169.  
  170.           Where:
  171.  
  172.                [eventname] - an optional name you can supply which
  173.                identifies the event for ARexx processing.  If you don't
  174.                supply a name, the event will be invisible to ARexx scripts. 
  175.                "eventname" must begin with an alpha character.  You can
  176.                specify as many events as you wish with the same eventname,
  177.  
  178.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  179. z
  180.  
  181.  
  182.  
  183.  
  184.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 4
  185.  
  186.                but ARexx commands that use "eventname" will only affect the
  187.                first event encountered, so it doesn't make any sense to do
  188.                so.  Since "eventname" is not used for actual event
  189.                processing, each identically named event will be processed. 
  190.                Note, "eventname" is not case sensitive, NazCron converts
  191.                all event names to uppercase before adding them to the event
  192.                list.  Thus "ImportantEvent" and "IMPORTANTEVENT" are the
  193.                same eventnames for NazCron purposes.
  194.       
  195.                The remainder of the fields are required.
  196.  
  197.                min - the minute at which "eventcommand" will be executed. 
  198.                Code the actual minute, minutes, range of minutes or "*" to
  199.                indicate every minute.  The numeric values may be provided
  200.                as:
  201.                     a single minute, e.g. 5 
  202.                     a group of minutes, e.g. 0,10,20,30  
  203.                     a range of minutes, e.g. 30-45 
  204.                     or a combination, e.g. 0,10,30,47-50,59
  205.  
  206.                hour, day, month and weekday - use the same format as "min".
  207.  
  208.                     Ranges of time values are:
  209.                          min:      0-59
  210.                          hour:     0-23 (0 = midnight)
  211.                          day:      1-31 (day is not checked for month. This
  212.                                    means that day 31, month 2 will be
  213.                                    allowed but, of course, never executed)
  214.                          month:    1-12
  215.                          weekday:  0-6 (0=Sunday, 6=Saturday)
  216.  
  217.  
  218.                eventcommand - is the AmigaDOS CLI command to be executed. 
  219.                It must contain all parameters as if typed from a CLI. Note
  220.                that there will be no CLI window for this command's output. 
  221.                If you wish to see the output, you must use redirection when
  222.                you type the command.
  223.                Example:
  224.                     Date >ram:date
  225.                Redirection is indicated by the ">" character.  Output that
  226.                would normally be sent to the CLI window for this command
  227.                would, instead, be sent to the file ram:date.
  228.  
  229.  
  230.      Cron event examples
  231.      -------------------
  232.  
  233.           * * * * * Date
  234.                Executes the ADOS Date command every minute.  Since re-
  235.                direction was not specified in the command, you will see no
  236.  
  237.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  238. z
  239.  
  240.  
  241.  
  242.  
  243.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 5
  244.  
  245.                evidence that Date was actually executed.
  246.  
  247.           DateToRam * * * * * Date >ram:date
  248.                Also executes the ADOS Date command every minute but the
  249.                date is written to the file "date" on the ram: disk.  Note,
  250.                "DateToRam" is the event name for this event, allowing it to
  251.                be manipulated from an ARexx script.
  252.  
  253.           0 19 * * * NewShell "newcon:0/30/640/30/BIX Time" from s:Bixtime
  254.                At 7pm every day, a shell will be opened, initially
  255.                executing the startup script "Bixtime" from the S:
  256.                directory.  This script is probably a reminder that it is
  257.                now ok to logon to BIX for non-prime time access.  The
  258.                script "Bixtime" might look something like:
  259.                     echo "It is 7pm.  It is now ok to logon to BIX"
  260.                     wait 10
  261.                     endcli
  262.  
  263.           0 10 * * 6 Access!
  264.                Every Saturday at 10am, NazCron will initiate the terminal
  265.                program Access! 
  266.  
  267.           0 0,12,17 * * 1-5 Execute ChangingOfTheGuard
  268.                The script "ChangingOfTheGuard" will be executed at
  269.                midnight, noon and 5pm every Monday through Friday. 
  270.  
  271.  
  272.      ARexx command processing
  273.      ------------------------
  274.  
  275.           NazCron supports a rich body of commands that may be introduced
  276.           from ARexx scripts or other ARexx interfaced programs.  In order
  277.           to send these commands to NazCron, the ARexx script must execute
  278.           the ARexx "address NAZCRON" statement prior to sending any
  279.           NazCron commands.  "NAZCRON" (note that this MUST be uppercase)
  280.           is the NazCron ARexx host address and must be the current host
  281.           when any NazCron command is invoked.  Consult the ARexx manual
  282.           for further information on communicating with ARexx host
  283.           processes.  
  284.  
  285.           The return code settings for all commands will be the standard
  286.           ARexx values as defined in the ARexx supplied header file
  287.           "errors.h".  These values are:
  288.  
  289.                RC_OK    = 0  
  290.                RC_WARN  = 5
  291.                RC_ERROR = 10
  292.                RC_FATAL = 20
  293.  
  294.           NazCron returns RC_OK when execution has completed successfully
  295.  
  296.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  297. z
  298.  
  299.  
  300.  
  301.  
  302.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 6
  303.  
  304.           and RC_WARN when a secondary result should have been returned
  305.           from the command but the script did not execute the 'options
  306.           results' statement.  RC_ERROR is returned for most errors
  307.           including unrecognized command and errors in command syntax. 
  308.           RC_FATAL is returned when NazCron is unable to allocate enough
  309.           memory to return the secondary result, or if a command is
  310.           received after shutdown is under way.
  311.  
  312.  
  313.      Individual NazCron ARexx commands
  314.      ---------------------------------
  315.  
  316.           SHUTDOWN
  317.                Terminates NazCron immediately.  All outstanding events are
  318.                purged and the timer is stopped.  No events will be executed
  319.                after SHUTDOWN is received, even if a timeout was about to
  320.                occur.
  321.       
  322.           SUSPEND
  323.                All event processing will be stopped until a RESUME is sent. 
  324.                NazCron will stop looking at events in the event list and
  325.                will ignore the CRONTAB file, even if the file has been
  326.                modified.  All ARexx commands may be executed and events in
  327.                the event list may still be manipulated with ARexx commands.
  328.  
  329.           RESUME
  330.                Resumes all event processing.
  331.  
  332.           LOCK_EVENTS
  333.                This locks file events in the event list.  Normally, the
  334.                CRONTAB file info block is examined each minute to determine
  335.                if the contents of the file have changed.  If the file
  336.                timestamp is different from the timestamp recorded the last
  337.                time the file was loaded, all events loaded from the file
  338.                are purged from the event list and the file is reloaded into
  339.                the event list.  CRONTAB date checking is NOT done when
  340.                events are locked.  If you are processing a CRONTAB file
  341.                that never changes, you can LOCK_EVENTS, thereby eliminating
  342.                the unnecessary overhead of examining the CRONTAB file each
  343.                minute.  Events may still be added or deleted from the event
  344.                list via ARexx commands; only the CRONTAB events are locked.
  345.  
  346.           UNLOCK_EVENTS
  347.                This unlocks the file events in the event list.  After this
  348.                command is executed, the CRONTAB file will be examined again
  349.                each minute.
  350.  
  351.           NEW_EVENT_FILE filename
  352.                "filename" must be the full path/file name of a new CRONTAB
  353.                file.  NazCron begins processing from the new file
  354.  
  355.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  356. z
  357.  
  358.  
  359.  
  360.  
  361.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 7
  362.  
  363.                immediately.  If events are "locked" (see LOCK_EVENTS above)
  364.                "filename" will be the file to be used once events have been
  365.                unlocked again.  Note that it is not necessary to issue
  366.                CLOSE_EVENT_FILE prior to opening a new file.  Caution: 
  367.                while NazCron assures that the file exists before doing the
  368.                switch, it does not verify the contents of the file. 
  369.                Consequently, the command may return with a successful
  370.                execution masking an error in the contents of the file.  If
  371.                there is a syntax error in the new file, all file events
  372.                will be purged.
  373.  
  374.           CLOSE_EVENT_FILE
  375.                Purges all events previously loaded from the event file and
  376.                stops examining the file.  Only ARexx introduced events will
  377.                be processed until the NEW_EVENT_FILE command is executed.
  378.  
  379.           ADD_EVENT cronevent
  380.                Adds "cronevent" to the event list.  "cronevent" must be in
  381.                the same format as defined above.  Note that if "eventname"
  382.                is not supplied, the event will be invisible to most ARexx
  383.                commands.
  384.  
  385.           DELETE_REXX_EVENT eventname
  386.                Deletes the event with "eventname" from the event list only
  387.                if the event was added from an ARexx script.  This command
  388.                may not be used to delete a CRONTAB event.  If the event
  389.                doesn't exist, RC_ERROR is set.  If there are more than one
  390.                ARexx event in the event list with the same "eventname",
  391.                only the first one in the list will be deleted.
  392.  
  393.           DELETE_EVENT eventname
  394.                Deletes any event with "eventname" from the event list.  If
  395.                the event doesn't exist, RC_ERROR is set.  If there are more
  396.                than one event in the event list with the same "eventname",
  397.                only the first one in the list will be deleted.
  398.  
  399.           PURGE_REXX_EVENTS
  400.                Deletes all ARexx introduced events from the event list,
  401.                even those that are invisible.  Events loaded from CRONTAB
  402.                will remain in the list untouched.
  403.  
  404.           SHOW_EVENT eventname
  405.                Returns the actual ASCII cronevent string in the 'result'
  406.                variable for the event named "eventname".  If the event
  407.                doesn't exist, RC_ERROR is set.  Both ARexx and CRONTAB
  408.                introduced events may be retrieved.  If there are more than
  409.                one event in the event list with the same "eventname", only
  410.                the first one in the list will be returned.
  411.  
  412.           LIST_EVENTS
  413.  
  414.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  415. z
  416.  
  417.  
  418.  
  419.  
  420.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 8
  421.  
  422.                Returns the eventnames of all named events in the event list
  423.                as a string of names separated by blanks.  If there are more
  424.                than one event in the event list with the same "eventname",
  425.                all will be returned.  Note, this command makes no
  426.                differentiation between events introduced by ARexx commands
  427.                and CRONTAB loaded events.   
  428.  
  429.           SHOW_STATUS
  430.                Returns the status of NazCron.  The format of the returned
  431.                message is:
  432.                     eventstate filestate cronfilename
  433.                where "eventstate" is either "ACTIVE" or "SUSPENDED",     
  434.                "filestate" is either "LOCKED" or "UNLOCKED", and
  435.                "cronfilename" is the full path name of the current event
  436.                file.
  437.  
  438.  
  439.      NazCron ARexx script example
  440.      ---------------------------- 
  441.  
  442.           /* NazCron ARexx script example*/
  443.  
  444.           /* Make sure we send all of our commands to NazCron */
  445.           address 'NAZCRON'
  446.  
  447.           /* Don't bother looking at the file again, it will not change */
  448.           'LOCK_EVENTS'
  449.  
  450.           'ADD_EVENT sidevent 48 15 * * * dh1:sid'
  451.           if (rc ~= 0) then say "ADD_EVENT error "|| rc
  452.  
  453.           'ADD_EVENT myevent * * * * * date >ram:rexxcron.date'
  454.           if (rc ~= 0) then say "ADD_EVENT error "|| rc
  455.  
  456.           'ADD_EVENT anotherevent * * * * * date >ram:anotherrexxcron.date'
  457.           if (rc ~= 0) then say "ADD_EVENT error "|| rc
  458.  
  459.           /* Get a list of all named events */
  460.           options results
  461.           'LIST_EVENTS'
  462.           if (rc ~= 0) then say "LIST_EVENTS error " || rc
  463.           else
  464.           do
  465.             eventlist = result
  466.  
  467.             /* display the names */
  468.             say eventlist
  469.             numwords = words(eventlist)
  470.  
  471.             /* If the list isn't empty, display the event connected with
  472.  
  473.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  474. z
  475.  
  476.  
  477.  
  478.  
  479.      July 20, 1989  NazCron V1.0 - Cron type event manager           Page 9
  480.  
  481.                each name */
  482.             if numwords > 0 then do
  483.               do j=1 to numwords
  484.                 event = word(eventlist,j)
  485.                 'SHOW_EVENT '|| event
  486.                 if (rc = 0) then say 'Event: ' || event || ', ' || result
  487.                 else say 'Event: ' || event || ' not found.'
  488.               end
  489.             end
  490.           end
  491.  
  492.  
  493.      Historical notes     
  494.      ----------------
  495.  
  496.           A short while ago, I stumbled on and installed a copy of AmiCron
  497.           to help with unattended maintenance on our BBS, Viva! Amiga!
  498.           While AmiCron was serviceable, and did pretty much what we
  499.           wanted, there was the problem of it requiring a CLI window.  With
  500.           the AmiCron window up 24 hours a day amidst lots of activity, it
  501.           was very easy to type a character into the window by mistake,
  502.           thus freezing AmiCron; it would simply stop working until I
  503.           noticed the stray characters and backspaced them out.  This
  504.           problem, and my fumble fingers, led to too many missed events. 
  505.           Since Rick Schaeffer and Christian Balzar, AmiCron authors, were
  506.           kind enough to include source with the package, I decided to
  507.           remove the CLI requirement by using the Lattice 5.0 startup
  508.           routine CBack.o.  On perusing the source, I discovered other
  509.           things about AmiCron that, I felt, could be improved.  
  510.  
  511.           AmiCron woke up every minute, opened the CRONTAB file, read all
  512.           of the records to execute any commands that were due, closed the
  513.           file and went back to sleep.  The process of sleeping for a
  514.           minute also required some unnecessary I/O.  It would create a
  515.           message port, allocate an EXTIO block, open the timer device, go
  516.           to sleep, wake up, close the timer device, free the EXTIO block
  517.           and delete the message port.  It went through all of these steps
  518.           every minute.  With the thought to make improvements to some of
  519.           this code, I began to modify the source.  I hadn't edited too
  520.           many lines before I realized that I really had to redesign the
  521.           thing to do what I wanted.
  522.  
  523.           The timer routines have been simplified, eliminating the DoIO
  524.           which waited for the timer to complete.  Instead NazCron does a
  525.           SendIO and the wait for timer completion occurs in a central loop
  526.           in "main".  In fact, I lifted this code from a commercial program
  527.           we are developing.  With this done, I was able to fold in Arexx
  528.           command handling so that the resulting program is an ARexx host. 
  529.           The timer request is allocated once when the program starts so
  530.           that each minute the timer functions simply compute the next
  531.  
  532.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  533. z
  534.  
  535.  
  536.  
  537.  
  538.      July 20, 1989  NazCron V1.0 - Cron type event manager          Page 10
  539.  
  540.           timeout period and issue another SendIO.
  541.  
  542.           A bigger change involves the actual handling of the events
  543.           themselves.  NazCron reads the CRONTAB file on startup, loads the
  544.           events into Exec Node structures and chains them in a List.  Each
  545.           time NazCron wakes up, it locks the current CRONTAB file,
  546.           examines the FileInfoBlock structure to determine, via timestamp,
  547.           if the file has changed since it was last loaded.  If it has, all
  548.           events previously loaded from the CRONTAB file are deleted from
  549.           the list and the file is reread and loaded back into memory with
  550.           any changes that were made to the file.  If the timestamp was not
  551.           changed, no more file accesses are necessary.  The list is then
  552.           scanned for events to be executed.
  553.  
  554.           Of course, ARexx handling was not present at all in the original
  555.           program.  NazCron was my first attempt to make useful ARexx
  556.           functions available in a program.  My initial design included a
  557.           small number of commands, but as I began programming, I couldn't
  558.           help but add virtually everything I could think of.  It was easy
  559.           to do.
  560.  
  561.           Surprisingly, with all of the new code for event list handling,
  562.           ARexx commands and new file I/O, the resulting program size is
  563.           about 1500 bytes SMALLER than the AmiCron program it replaces. 
  564.           Most of the decrease is probably attributable to the fact that I
  565.           Amiga-tized it, the rest to the superb Lattice 5.0 optimization
  566.           algorithms.  NazCron has no remaining traces of portability, so
  567.           don't expect to see it on your local GS or COCO real soon now.
  568.  
  569.  
  570.      Thanks to:
  571.      ----------
  572.  
  573.           Lattice for the great 5.0 package - especially CPR, 
  574.           Bill Hawes for ARexx, 
  575.           Eric Lavitsky for his well structured and information-packed     
  576.                Amiga programming course, 
  577.           Rick Schaeffer and Christian Balzar for the original AmiCron,
  578.           Jay Miner (and friends) for the Amiga and  
  579.           My family for putting up with me programming while they baked    
  580.                their brains out on the beach.
  581.  
  582.           I wouldn't have written this program without you guys.
  583.       
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.    Copyright 1989 by Don Nafis and Nazlo Associates Ltd.  All rights reserved.
  592. c