Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Application Packaging Developer's Guide
Previous Next

Modifying crontab Files During Installation

This case study modifies crontab files during package installation.

Techniques

This case study demonstrates the following techniques:

  • Using classes and class action scripts

    For more information, see Writing Class Action Scripts.

  • Using the crontab command within a class action script

Approach

The most efficient way to edit more than one file during installation is to define a class and provide a class action script. If you used the build class approach, you would need to deliver one build class script for each crontab file edited. Defining a cron class provides a more general approach. To edit crontab files with this approach, you must:

  • Define the crontab files that are to be edited in the prototype file.

    Create an entry in the prototype file for each crontab file that will be edited. Define the class as cron and the file type as e for each file. Use the actual name of the file to be edited.

  • Create the crontab files for the package.

    These files contain the information you want added to the existing crontab files of the same name.

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

    The sample i.cron script performs the following procedures:

    • Determines the user ID (UID).

      The i.cron script sets the variable user to the base name of the cron class script being processed. That name is the UID. For example, the base name of /var/spool/cron/crontabs/root is root, which is also the UID.

    • Executes crontab using the UID and the -l option.

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

    • Pipes the output of the crontab command to a sed script that removes any previous entries added with this installation technique.

    • Puts the edited output into a temporary file.

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

    • Executes crontab with the same UID and gives it the temporary file as input.

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

    The r.cron script is the same as the installation script except there is no procedure to add information to the crontab file.

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

Case Study Files

The i.cron and r.cron scripts described below are executed by superuser. Editing another user's crontab file as superuser may have unpredictable results. If necessary, change the following entry in each script:

crontab $user < /tmp/$$crontab ||

to

su $user -c "crontab /tmp/$$crontab" ||
The pkginfo Command
PKG=case7
NAME=Case Study #7
CATEGORY=application
BASEDIR=/opt
ARCH=SPARC
VERSION=Version 1.0
CLASSES=cron
The prototype File
i pkginfo
i i.cron
i r.cron
e cron /var/spool/cron/crontabs/root ? ? ?
e cron /var/spool/cron/crontabs/sys ? ? ?
The i.cron Installation Class Action Script
# 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
The r.cron Removal Class Action Script
# 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 
crontab File #1
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
crontab File #2
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

Note - If editing of a group of files will increase total file size by more than 10K, supply a space file so the pkgadd command can allow for this increase. For more information on the space file, see Reserving Additional Space on a Target System.


Previous Next

 
 
  Published under the terms fo the Public Documentation License Version 1.01. Design by Interspire