DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Packaging your software applications

6. Modify crontab files during installation

This case study modifies a number of crontab files during package installation.

Techniques

This case study shows examples of the following techniques:

Approach

You could use the build class and follow the approach shown for editing /etc/inittab in case study 5c except that you want to edit more than one file. If you used the build class approach, you would need to deliver one for each crontab file edited. Defining a cron class provides a more general approach. To edit a crontab file with this approach, you must:

  1. Define the crontab files that will be edited in the prototype(F) file.

    Create an entry in the prototype(F) file for each crontab file which will be edited. Define their class as cron and their file type as e. Use the actual name of the file to be edited, as shown in the example.

  2. Create the crontab files that will be delivered with the package.

    These files contain the information you want added to the existing crontab files of the same name. See the sample root and sys files for two examples.

  3. Create an installation class action script for the cron class.

    The i.cron script performs the following procedures:


    a.
    Calculates the user ID.

    This is done by setting the variable user to the base name of the cron class file being processed. That name equates to the user ID. For example, the basename of /var/spool/cron/crontabs/root is root (which is also the user ID).


    b.
    Executes crontab using the user ID and the -l option.

    Using the -l options tells crontab to send the standard output the contents of the crontab for the defined user.


    c.
    Pipes the output of the crontab command to a sed(C) script that removes any previous entries that have been added using this installation technique.

    d.
    Puts the edited output into a temporary file.

    e.
    Adds the data file for the root user ID (that was delivered with the package) to the temporary file and adds a tag so that you will know from where these entries came.

    f.
    Executes crontab with the same user ID and give it the temporary file as input.

  4. Create a removal class action script for the cron class.

    The sample removal script is the same as the installation script except that there is no procedure to add information to the crontab file.

These procedures are performed for every file in the cron class.

pkginfo file

   PKG='case6'
   NAME='Case Study 6'
   CATEGORY='application'
   ARCH='3b2'
   VERSION='Version 1.0'
   CLASSES='cron'

prototype file

   i pkginfo
   i i.cron
   i r.cron
   e cron /var/spool/cron/crontabs/root ? ? ?
   e cron /var/spool/cron/crontabs/sys ? ? ?

Installation class action script (i.cron)

   # PKGINST parameter provided by installation service
   

while read src dest do user=`basename $dest` || exit 2

(crontab -l $user | sed -e "/#$PKGINST$/d" > /tmp/$$crontab) || exit 2

sed -e "s/$/#$PKGINST/" $src >> /tmp/$$crontab || exit 2

crontab $user < /tmp/$$crontab || exit 2 rm -f /tmp/$$crontab done exit 0

Removal class action script (r.cron)

   # PKGINST parameter provided by installation service
   

while read path do user=`basename $path` || exit 2

(crontab -l $user | sed -e "/#$PKGINST$/d" > /tmp/$$crontab) || exit 2

crontab $user < /tmp/$$crontab || exit 2 rm -f /tmp/$$crontab done exit 0

root crontab file (delivered with package)

   41,1,21 * * * * /usr/lib/uucp/uudemon.hour > /dev/null
   45 23 * * * ulimit 5000; /usr/bin/su uucp -c "/usr/lib/uucp/uudemon.cleanup" >
   /dev/null 2>&1
   11,31,51 * * * * /usr/lib/uucp/uudemon.poll > /dev/null

sys crontab file (delivered with package)

   0 * * * 0-6 /usr/lib/sa/sa1
   20,40 8-17 * * 1-5 /usr/lib/sa/sa1
   5 18 * * 1-5 /usr/lib/sa/sa2 -s 8:00 -e 18:01 -i 1200 -A

Next topic: 7a. Create a Set Installation Package
Previous topic: build script (/home/case5c/inittab.build)

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005