Está en la página 1de 18

V4.

1
Student Notebook

Uempty

Unit 15. Scheduling


What this unit is about
This unit describes how jobs can be scheduled on the system.

What you should be able to do


After completing this unit, you should be able to: Use crontab files to schedule jobs on a periodic basis Use the at command to schedule a job or series of jobs at some time in the future Use the batch command to schedule jobs in a queue, to alleviate immediate system demand

How you will check your progress


Accountability: Checkpoint questions Exercise

References
Online Online AIX 6.1 Commands Reference AIX 6.1 Files Reference

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-1

Student Notebook

Unit objectives
After completing this unit, you should be able to: Use crontab files to schedule jobs on a periodic basis Use the at command to schedule a job or series of jobs at some time in the future Use the batch command to schedule jobs in a queue to alleviate immediate system demand

Copyright IBM Corporation 2008

Figure 15-1. Unit objectives

AU1412.0

Notes:

15-2 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Student Notebook

Uempty

The cron daemon


Responsible for running scheduled jobs Starts:
crontab command events (regularly scheduled jobs) at command events (one time only execution at specified time) batch command events (run when CPU load is low)

1 2:3 5
Copyright IBM Corporation 2008

Figure 15-2. The cron daemon

AU1412.0

Notes: Function of the cron daemon


The system process that allows batch jobs to be executed on a timed basis is the cron daemon. Many people rely on cron to execute jobs. Jobs are submitted to the cron daemon in a number of different ways: - The at and batch facilities are used to submit a job for one-time execution - crontab files are used to execute jobs periodically - hourly, daily, weekly

Starting of cron
The cron process is usually started at system startup by /etc/inittab. It runs constantly as a daemon. If killed, it is automatically restarted.

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-3

Student Notebook

Changing how cron event types are handled


The /var/adm/cron/queuedefs file defines how the system handles different cron daemon event types. The file specifies the maximum number of processes per event type to schedule at one time, the nice value of the event type, and how long to wait before retrying to execute a process. This file is empty as shipped, but can be modified to change how the cron daemon handles each event type. For example, by default, crontab events are inspected every 60 seconds, run at a nice value of 2 higher than the default, and there may be up to 100 executing simultaneously. This may be changed by modifying the /var/adm/cron/queuedefs file. For example, if crontab jobs were to run at a nice value of 10 higher than the default with files inspected every two minutes and with up to 200 jobs allowed, then the following entry should be made to the file: c.200j10n120w | | | | | | | wait period (in seconds) | | | | | nice value | | | jobs | cron

15-4 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Student Notebook

Uempty

crontab files
Used to start regularly occurring jobs Schedule is defined in: /var/spool/cron/crontabs/$USER Files to control crontab privileges of users:
/var/adm/cron/cron.deny lists users who cannot use crontab /var/adm/cron/cron.allow lists users who can use crontab

An empty cron.deny exists by default

Copyright IBM Corporation 2008

Figure 15-3. crontab files

AU1412.0

Notes: Scheduling a job


The cron daemon starts processes at specified times. It can be used to run regularly scheduled jobs using files in the /var/spool/cron/crontabs directory, or it can be used to schedule a command for one-time-only execution using the at command.

The /var/adm/cron/cron.deny file


All users by default have the privilege to set up scheduled jobs to be monitored by cron. This is because the file /var/adm/cron/cron.deny, which denies privileges to users, exists and is empty. As the administrator, you can restrict access to cron by adding user names to this text file.

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-5

Student Notebook

The /var/adm/cron/cron.allow file


Another file that also restricts users privileges is /var/adm/cron/cron.allow. To use this file, you should remove the cron.deny file and create the cron.allow file to list the users that are allowed to use cron. If cron.allow exists and is empty, NO user is able to use cron, that includes root. If both cron.allow and cron.deny exist, then cron.allow is the file that is used. If neither cron.allow nor cron.deny exists, then only root can use cron.

15-6 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Student Notebook

Uempty

Format of a crontab file


To view current crontab: # crontab -l
... #0 3 #45 2 ... 0 11 0 12 0 15 ... * * * /usr/sbin/skulker * * 0 /usr/lib/spell/compress * * * /usr/bin/errclear -d S,O 30 * * * /usr/bin/errclear -d H 90 * * * /usr/lib/ras/dumpcheck >/dev/null 2>&1

Format of entries:
minute hour date-of-month month day-of-week command
Copyright IBM Corporation 2008

Figure 15-4. Format of a crontab file

AU1412.0

Notes: Viewing a crontab file


Each user can view their crontab file by using the command crontab -l. The users crontab file contains the schedule of jobs to be run on behalf of that user. There is a separate crontab file for each user of the crontab facility. This file is located in /var/spool/cron/crontab/$USER.

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-7

Student Notebook

Format of crontab file entries


The format for the lines in this file is as follows: minute (0-59) hour (0-23) date of the month (1-31) month of the year (1-12) day of the week (0-6, where 0=Sunday, 1=Monday, and so forth) command Fields are separated by spaces or tabs. To indicate a field is always true, use an asterisk (*). To indicate multiple values in a field, use a comma (,). A range can also be specified by using a dash (-).

Examples of crontab entries


Here are some examples of crontab entries: - To start the backup command at midnight, Monday through Friday: 0 0 * * 1-5 /usr/sbin/backup -0 -u -q -f /dev/rmt0 - To execute a command called script1 every 15 minutes between 8 AM and 5 PM, Monday through Friday: 0,15,30,45 8-17 * * 1-5 /home/team01/script1

15-8 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Student Notebook

Uempty

Editing a crontab file


One way to edit a crontab file:
# crontab -e

A safer method:
# crontab -l > /tmp/crontmp # vi /tmp/crontmp # crontab /tmp/crontmp

Copyright IBM Corporation 2008

Figure 15-5. Editing a crontab file

AU1412.0

Notes: Creating or updating a crontab file


To schedule a job, you must create a crontab file. The cron daemon keeps the crontab files in memory, so you cannot update the crontab entries by just modifying the file on disk.

Using crontab -e to edit the crontab file


To edit the crontab file, one method is to use crontab -e. This opens up your crontab file with the editor set with the EDITOR variable. Edit the file as you normally would any file. When the file is saved, the cron daemon is automatically refreshed.

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-9

Student Notebook

Another method of updating your crontab file


The crontab -l command always shows the crontab file that cron is using on your behalf. Another method to update the file is to use the command crontab -l > mycronfile. This creates a copy of the current crontab file and allows you to safely edit the mycronfile file without affecting the current crontab file. To submit your changes, use the command: crontab mycronfile. The content of the mycronfile file replaces the content of your file in the crontab directory and refreshes the cron daemon, all at once. Now, you also have a backup of the crontab file in mycronfile.

Removing your crontab file


Use the command crontab -r if you would like to remove your current crontab file.

15-10 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Student Notebook

Uempty

The at and batch commands


The at command submits a uniquely occurring job to be run by cron at a specified time:
# at now +2 mins banner hello > /dev/pts/0 <ctrl-d> job user.time.a will be run at date

The batch command submits a job to be run when the processor load is sufficiently low:
# batch banner hello > /dev/pts/0 <ctrl-d>

Copyright IBM Corporation 2008

Figure 15-6. The at and batch commands

AU1412.0

Notes: Use of the at command


The at command submits a job for cron to run once (rather than on a recurring basis) at a specified time. It reads the commands to execute from standard input. The at command mails you all output from standard output and standard error for the scheduled commands, unless you redirect that output. Examples of keywords or parameters that can be used with at are: noon, midnight, am, pm, A for am, P for pm, N for noon, M for midnight, today, tomorrow. The time can be specified as an absolute time or date (for example, 5 pm Friday), or relative to now (for example, now + 1 minute). The Bourne shell is used by default to process the commands. If -c is specified the C shell is run, and if -k is specified the Korn shell is run. If you specify the -m option, at sends you mail to say that the job is complete.

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-11

Student Notebook

Controlling use of at
The at command can only be used by root unless one of the following files exists: - /var/adm/cron/at.deny If this file exists, anybody can use at except those listed in it. An empty at.deny file exists by default. Therefore, all users can use at by default. - /var/adm/cron/at.allow If this file exists, only users listed in it can use at (root included).

Use of the batch command


The batch command submits a job to be run when the processor load is sufficiently low. Like the at command, the batch command reads the commands to be run from standard input and mails you all output from standard output and standard error for the scheduled commands, unless you redirect that output.

15-12 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Student Notebook

Uempty

Controlling at jobs
To list at jobs:
at -l [user] atq [user] # at l root.1118077769.a root.1118078393.a test2.1118079063.a Mon Jun Mon Jun Mon Jun 6 10:09:29 2007 6 10:19:53 2007 6 10:31:03 2007

To cancel an at job:
at -r job atrm [job | user] # at -r test2.1118079063.a at file: test2.1118079063.a deleted

To cancel all your at jobs:


atrm -

Copyright IBM Corporation 2008

Figure 15-7. Controlling at jobs

AU1412.0

Notes: Listing at jobs


To list at jobs use the at -l command or the atq command. The root user can look at another user's at jobs by using the command atq <user>.

Removing at jobs
To cancel an at job use at -r or atrm followed by the job number. Use the command atrm - (placing nothing after the - character) to cancel all of your jobs. The root user can cancel all jobs for another user using atrm <user>.

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-13

Student Notebook

Documenting scheduling
Have a copy of each user's crontab file Have a copy of the /etc/inittab file

Scheduling Records

Copyright IBM Corporation 2008

Figure 15-8. Documenting scheduling

AU1412.0

Notes: Overview
It is important to have correct up to date information regarding your system, in case of an unexpected system failure. Maintain as much documentation as possible about all aspects of the system by following the recommendations we have given throughout the course.

15-14 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Student Notebook

Uempty

Checkpoint
1. True or False? The at.allow and at.deny files must be used to specify which users are allowed and denied use of the at command. 2. Give a crontab entry that would specify that a job should run every Thursday at 10 past and 30 minutes past every hour. _____________________________________________ 3. How would you schedule a script named myscript, to run 10 minutes from now? _____________________________________________ _____________________________________________ _____________________________________________ _____________________________________________
Copyright IBM Corporation 2008

Figure 15-9. Checkpoint

AU1412.0

Notes:

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-15

Student Notebook

Exercise 17: Scheduling

Using at Using batch Using crontab files

Copyright IBM Corporation 2008

Figure 15-10. Exercise 17: Scheduling

AU1412.0

Notes: Introduction
This lab gives you the opportunity to schedule jobs using both at and crontab. The exercise can be found in your Student Exercises Guide.

15-16 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Student Notebook

Uempty

Unit summary

The cron daemon is responsible for running scheduled jobs. The crontab files are used to schedule recurring jobs. The at command is used to schedule a command for one time only execution. The batch command is used to submit a job to be run when the processor load is sufficiently low.

Copyright IBM Corporation 2008

Figure 15-11. Unit summary

AU1412.0

Notes:

Copyright IBM Corp. 1997, 2008


Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Unit 15. Scheduling

15-17

Student Notebook

15-18 AIX System Administration I

Copyright IBM Corp. 1997, 2008

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

También podría gustarte