Periodic Processes - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Periodic Processes

Description:

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 ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 18
Provided by: TheHarri8
Category:

less

Transcript and Presenter's Notes

Title: Periodic Processes


1
Periodic Processes
  • Chapter 9

2
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 email when a problem is
    discovered.

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.

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

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 youre 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

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

7
2. The format of crontab files
  • Example 1
  • 45 10 1-5
  • Means 1045 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.

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?

9
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

10
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.

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
    roots crontab
  • Most UNIX systems often come with some crontab
    entries preinstalled for you.
  • So, lets look at some of the tasks

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

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 lostfound
    type d -mtime 3 exec /bin/rm rf

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

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.

16
5. Vendor specifics
  • Red Had and FreeBSD use a free version of cron
    called Vixie-cron

17
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com