Presentation is loading. Please wait.

Presentation is loading. Please wait.

Periodic Processes Chapter 9.

Similar presentations


Presentation on theme: "Periodic Processes Chapter 9."— Presentation transcript:

1 Periodic Processes Chapter 9

2 Chapter 9 - Periodic Processes
Introduction The key to staying in control of your system is to automate as many tasks as possible. For example, and adduser program can add new users faster than you can, with a smaller chance of making mistakes. Almost any task can be encoded in a shell, Perl, or expect script. It is often useful to have a script or command executed without any human intervention For example, you might want to have a script verify (say, every half hour) that your network routers and bridges are working correctly and have it send you when a problem is discovered. Chapter 9 - Periodic Processes

3 1. cron: schedule commands
Under UNIX, periodic execution is handled by the cron daemon. cron starts when the system boots and remains running as long as the system is up. cron reads one or more configuration files containing lists of command lines and times at which they are to be invoked. The commands are executed by sh, so almost anything you can do from the shell can be done by cron. Chapter 9 - Periodic Processes

4 1. cron: schedule commands
A cron configuration file is called a “crontab,” short for cron table. All crontab files are stored in a single system directory, where cron knows where to look for them The crontab command transfers crontab files to and from this directory. Typically there is (at most) one crontab file per user Files are named with the loginname of the user they belong to, and cron uses these filenames to figure out which UID to use when running the commands that each file contains Chapter 9 - Periodic Processes

5 1. cron: schedule commands
Cron normally does it work silently, but some versions keep a log file. The log file grows quickly and is rarely useful Leave logging off unless you’re debugging a specific problem. Most crons do not compensate for commands that are missed while the system is down. Some do not understand daylight savings Chapter 9 - Periodic Processes

6 2. The format of crontab files
All the crontab files on a system share a common format. Comments are introduced with a # in the first column Each non comment line contains six fields minute hour day month weekday command The first five are separated by whitespace. Whitespace in the command is taken literally Chapter 9 - Periodic Processes

7 2. The format of crontab files
Example 1: 45 10 * * 1-5 Means 10:45 am Monday through Friday Example 2: 0,30 * 13 * 5 Means every half hour on Friday AND every half hour on the 13th, It does not mean every half hour on Friday the 13th. Chapter 9 - Periodic Processes

8 2. The format of crontab files
The command is the sh command line to be executed It can be any valid shell command and should not be quoted. Usually any output produced by a cron command is mailed to the owner of the crontab Example: 20 1 * * * find /tmp –atime + 3 –exec rm –f {} ‘;’ What does it do? Chapter 9 - Periodic Processes

9 Chapter 9 - Periodic Processes
3. Crontab management crontab filename Installs filename as your crontab (replaces old file) crontab -e Checks out a copy of your crontab file and invokes your editor on it. As specified by the EDITOR environment variable crontab -l Lists the contents of your crontab file to standard output crontab -r Removes your file Chapter 9 - Periodic Processes

10 Chapter 9 - Periodic Processes
3. Crontab management Most systems allow root to supply a username argument so that other users crontab files may be viewed, edited, or deleted crontab –r jsmith By default, all users can submit crontab files to cron cron.allow and cron.deny allow you to override this policy It is important to note that access is controlled by crontab (not by cron), so if a user can sneak a crontab file into the appropriate directory cron will blindly execute it. Chapter 9 - Periodic Processes

11 4. Some common uses for cron
A number of tasks are especially suited for invocation by cron. These usually make up the bulk of the material in root’s crontab Most UNIX systems often come with some crontab entries preinstalled for you. So, let’s look at some of the tasks Chapter 9 - Periodic Processes

12 4. Some common uses for cron
Cleaning the filesystem core files Useful for software developers, but for administrators they are usually a waste of space. NFS When a file is deleted on an NFS server (but still is used remotely) it will often rename the file .nfsxxx /tmp and /var/tmp files Chapter 9 - Periodic Processes

13 4. Some common uses for cron
Sample cron lines find / -xdev –name code –atime +7 –exec rm –f {} ‘;’ find / -xdev –atime +3 ‘(‘ –name ‘#*’ –o name ‘.#*’ –o name ‘*.CKP’ –o –name ‘*~’ –o name ‘.nfs*’ ‘)’ –exec rm –f {} ‘;’ find /var/preserve –mtime +14 –exec rm –f {} ‘;’ cd /tmp; find . ! –name . ! –name lost+found –type d -mtime +3 –exec /bin/rm –rf {} ‘;’ Chapter 9 - Periodic Processes

14 4. Some common uses for cron
Network distribution of configuration files If you are running a network of machines, it is often convenient to maintain a single network-wide version of configuration files Examples: Mail aliases NIS Chapter 9 - Periodic Processes

15 4. Some common uses for cron
Rotating log files UNIX log files generally grow without bound until they are manually reset. You could just truncate them at various intervals A more conservative strategy is to “rotate” log files by keeping several older versions of each one. See page 205 for more info on this. Chapter 9 - Periodic Processes

16 Chapter 9 - Periodic Processes
5. Vendor specifics Red Had and FreeBSD use a free version of cron called Vixie-cron Chapter 9 - Periodic Processes

17 Chapter 9 - Periodic Processes


Download ppt "Periodic Processes Chapter 9."

Similar presentations


Ads by Google