Objectives| Introduction| cron| Quotas and Process Resource Limits| Process Resource Limits| The BSD Disk Quota System| BSD Accounting| syslog| Conclusions| Review Questions
Most of these responsibilities require no human interaction other than to start the command. Rather than have the Administrator start these jobs manually, UNIX provides a mechanism that will automatically carry out certain tasks at set times.
crond is a system daemon that will execute other programs at the times specified in the appropriate configuration files. The daemon is normally started in one of the system's start up files (/etc/rc*).
The configuration files that control the operation of cron are called crontab files (cron tables). These files contain information about the time, date and command to execute. Different versions of UNIX store these crontab files in different locations and use a slightly different format.
On most systems the crontab files can only be modified using the crontab command. Even though the crontab files are text files they should not be modified using an editor.
Table 16.1 summarises the various components of the cron system.
Component Purpose crond the daemon that reads the configuration files and runs the commands crontab the command used to create the configuration files cron.log a file used to store the output and results of commands executed by crond /usr/spool/cron/crontabs the directory in which the configuration files are kept cron.allow cron.deny files used to control which users can create their own crontab entries (only available on some systems) Table 16.1. cron Files, Commands and Daemons.
The crontab files are text files with one entry per line. Each entry contains either six (SysV) or seven (some BSD systems) fields separated by white space. Table 16.2 summarises the fields of a cron configuration file.
The additional field on some BSD sysetms indicates the username of the user the entry belongs to. This field isn't needed under SysV systems as each user has their own crontab file.
Field Purpose minute minute of hour, 00 to 59 hour hour of the day, 00 to 23 (military time) day day of the month, 1 to 31 month month of the year, 1 to 12 weekday day of the week, either 1 to 7, or 0 to 6, username name of user executing command command command to execute Table 16.2. Fields of a cron Entry.Weekdays usually start with Sunday as either 0 or 1. However a few systems start the week on Monday. The manual pages on cron or crontab should list the format used a particular system.
Comments can be used and are indicated using the # symbol. Anything that appears after a # symbol until the end of that line is considered a comment and is ignored by crond.
The first five fields use any one of the following formats.
For example:
every hour (when minutes=0) display Cuckoo Cuckoo on the system console 0 * * * * echo Cuckoo Cuckoo > /dev/console at half past the hour, between 9 and 5, for every day of January which is a Sunday, Wednesday or Saturday, append the date to the file date.file 30 9-17 * 1 0,3,6 echo `date` >> /date.fileThe commands are run by the crond daemon. This means that they are not associated with any particular terminal and so there is no place for them to get standard input or put standard output and standard error. This means if the output of these commands are to be used it must be redirected. Specific log files (like date.file from the example above) or electronic mail are common destinations.
Some systems provide a file cron.log that is used to store the output of commands executed by crond.
Exercise 16-1. Using the manual pages discover the following
These files contain a list of usernames, one username to a line. These files specify who can and who can't use the cron system using the following rules if a username appears in cron.allow that user can use cron, if a username appears in cron.deny that user cannot use cron, if neither file exists only root can use cron, and if cron.allow does not exist and cron.deny does but is empty then everyone can use cron.
The location of these files can differ from system to system.
1. crontab [file] or
2. crontab [-e | -r | -l ] [username]
Version 1 is used to replace an existing crontab file with the contents of standard input or the specified file.
Version 2 makes use of one of the following command line options
For example:
create a normal file that contains my crontab file crontab -l > my.crontab edit the normal file using an editor and make the necessary modifications vi my.crontab replace the existing crontab file with the new one crontab my.crontabExercise 16-3. What would the contents of the cron.allow/cron.deny files be so that
The choice of whether or not to implement quotas and process resource limits is up to the Systems Administrator. The decision may depend on
Both systems use the concept of
C Shell Korn Shell Resource cputime time total accumulated CPU time filesize file largest possible file size datasize data size of a process' data segment stacksize stack size of a process' stack coredumpsize coredump size of a core file memoryuse memory amount of memory Table 16.3. Possible Process Resource Limits.Process limits suffer from a number of problems
For example:
The user jonesd might have one set of quotas for the /home file system and another set of quotas for the /usr/local file system. The user munstert can have a different quota under /usr/local and no quota under /home.
The system allows the specification of two limits (similar to process resource limits)
Command Purpose quota display a user's disk usage and quota quotacheck ensure that quota records match disk usage quotaon turn quotas on quotaoff turn quotas off repquota report on implemented quotas edquota modify a user's quota Table 16.4. Summary of Quota Commands.For quotas to work the following must be carried out
Each partition for which quotas have been enabled will have its own quota control file. The file is kept in the root directory of the partition and contains the following information
For example:
A system has the following /etc/fstab file /dev/hdb1 swap swap defaults /dev/hda2 / ext2 defaults /dev/hdb2 /home ext2 defaults,usrquota /dev/hda1 /home/ftp/pub ext2 defaults none /proc proc defaults Quotas have been turned on for the /home parition (notice) the additional option usrquota. This means there should be a quotas (or on this system quota.user) file in the root directory of that partition. bash$ ls -l /home/quota.user -rw------- 1 root students 164368 Sep 21 13:37 /home/quota.user bash$ quota jonesd Disk quotas for user jonesd (uid 975): File system blocks quota limit grace files quota limit grace /dev/hdb2 7 9 16 6* 5 10 none This user has a very small quota and is actually over the soft limit on the number of files allowed (notice the 6*)Quotas are set for individual users by root using the edquota command. This command enters the default editor (defined by the shell variable EDITOR) and allows the root user to modify the the assigned quotas. When the editor is exited the new modified quotas will be added to the quotas file.
For example:
The following provides an example of what the user sees when they use edquota bash$ edquota jonesd Quotas for user jonesd: /dev/hdb2: blocks in use: 7, limits (soft = 9, hard = 15) inodes in use: 6, limits (soft = 5, hard = 10) The root user can now modify these numbers to increase or decrease the user's quota.The quotacheck command is used to ensure that the record of current disk usage stored in the quotas file is correct. When quotacheck is executed it searches throughout the file system and summarises how many disk blocks and i-nodes each individual user owns and updates the statistics stored in the quotas file.
Users adding or deleting files at the same time quotacheck is being executed can result in inconsistent results. For this reason the quotacheck command should only be executed when there are no users on the system. As a result it is normally executed during system startup before users can login.
For example:
echo -n 'checking quotas:' > /dev/console /etc/quotacheck -a -p > /dev/console 2>&1 /etc/quotaon -a
For example:
The following example is of an /etc/vfstab file from a SysVR4 machine. /dev/sd0a / 4.2 rw 1 1 to /dev/sd0a / 4.2 rq 1 1 The change from w to q is a change from write to write with quotas.
touch quotas do this as root chmod u=rw quotas
Exercise 16-6. Create a new user and set some very strict quotas that allow a very low number of files and blocks. Experiment with the user account to see what happens when the soft and hard limits are exceeded.
Both the BSD and SysV accounting systems store similar information but use different commands to summarise and display the information. SysV accounting relies on a greater number of shell scripts and C programs. SysV accounting will not be examined in this section.
The system administrator has two responsibilities with regards to accounting
The BSD accounting information is recorded by the by the kernel appending information to a specific accounting file. A number of specific commands are provided to examine the contents of those files. Table 16.5 summarises what information is kept, in what files and what commands can be used to examine the information.
Information Commands Files processes accton, sa, specified by accton command line, lastcomm usually /usr/adm/acct * current users w, who /etc/utmp connect time ac, last /usr/adm/wtmp disk usage quot, du no file printer usage pac defined by af entry in printers printcap entry *the file needs to exists beforehand Table 16.5. Summary of BSD Accounting Information.The files that are written to by the accounting system will continue to grow and take up disk space. They should regularly be pruned. The administrator must also decide whether or not to archive these files. The simplest method to deal with these accounting files is to have entries in the crontab so that the system will automatically take care of the problem.
For example:
Summarise the accounting file, this produces a much smaller file. # summarise /usr/adm/acct file into /usr/adm/savacct 0 1 * * 1-6 /etc/sa -s Truncate the wtmp file to nothing 0 2 1 * * cp /dev/null /usr/adm/wtmpThe administrator must decide whether or not to save the old version of the accounting files for future use before truncating them.
if [ -f /var/adm/acct ] then accton /var/adm/acct echo -n ' accounting' > /dev/console fiThe information is appended onto the file specified in the accton command and is usually /var/adm/acct (on some systems /usr/adm/acct). This file becomes very lengthy reasonably quickly. The sa command can be used to produce a file /var/adm/savacct that is formed by merging the records in the acct file.
This information can be examined using the
syslogd provides a central distribution point for status information and error messages and provides the Systems Administrator with the ability to direct these messages to be
Where the messages are sent is controlled by the syslog configuration file /etc/syslog.conf. syslog.conf is a text file with the following format
facility.level[;facility.level...] destinationfacility describes where the information is coming from. Some of the possible sources are listed in Table 16.6. level describes the severity of the information (Table 16.7) and destination specifies where the message is to be sent.
Value Source kern the kernel mail the mail system lpr the printing system daemon the various system daemons auth the login authentication system Table 16.6. Facilities that may use syslog. Level Description emerg a system panic alert an error that requires immediate action crit a critical error err errors warn warnings notice non-critical messages info informative messages debug debugging information Table 16.7. Levels of syslog messages.For example:
The following is an example /etc/syslog.conf taken from a Linux box. # # NOTE: YOU HAVE TO USE TABS HERE - NOT SPACES. # kern.* /home/megan/kern.messages *.=info;*.=notice /usr/adm/messages *.=debug /usr/adm/debug *.warn /usr/adm/syslogExercise 16.7. Examine the syslog.conf file on your system (if it supports it) and the various log files the syslogd sends the messages.
Exercise 16.8. Modify the syslog.conf file so that the most serious messages are sent to the system console.
The UNIX operating system provides a number of systems that allow the Systems Adminstrator to
16.2. Describe the effects of the following crontab entry
* * 1 1,6,12 0-3 echo this day is 'date'>> date.log
16.3. Describe how the BSD disk quota system works.
16.4. What is the purpose of the syslog system?
David Jones (author)