荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: Lg (创造人生的传奇), 信区: Linux
标  题: Using Crontab with Linux
发信站: BBS 荔园晨风站 (Mon Dec  6 10:10:19 1999), 站内信件

Using Crontab with Linux
Overview

In any system, an important funciton is scheduling tasks to be run. Users and
administrators alike often pay hundreds of dollars for Windows tools to run
programs at specified times. In Linux, there is a tool called 'cron' which will
handle all of your scheduling needs. Best of all, it's free, and it comes with
Linux.


Installation

Cron is available with every Linux distribution. It has two main programs, crond
and crontab. crond is the daemon that runs in the background and makes sure
that programs get run when they're scheduled to be run. crontab is the program
that allows you to modify the programs that you have scheduled to run.
/etc/crontab is the file that stores sytem scheduling information; each user has
their own crontab file in /var/spool/cron.


Configuration

Cron knows what to run when by setting up crontab files. These files are of a
particular format: since you're scheduling a task, you need to indicate when
and what. You need to tell cron the minutes, hours, days, months, and years to
run the task, and then tell cron the command you want run. You can use
asterisks to indicate all possible values. The command to edit your crontab file
is `crontab -e`, which will bring up an editor window and allow you to edit your
crontab file.

For example, to run 'rm -rf ~/tmp' at midnight Sunday night every week, run
`crontab -e`, and add the line:

0 0 0 * * rm -rf ~/tmp

This indicates that the command should be run on the zeroth minute of the
zeroth hour (midnight) of the zeroth day (Sunday) of every month of every year.
(This could only be done by root, because of the command.)


Usage

Once you've set up your crontab file (and that of the system's, if you're root),
you don't have to worry about it again, until you want to add or change your
configuration. To list your current crontab entries, use `crontab -l`; to
delete all
of them, use `crontab -r`.


Tips

You can create a crontab file without using crontab, but use crontab to set the
file to be your crontab file. Use the command `crontab file`, where 'file' is
the
file you want to use. This will replace your old crontab file, however, not
append
to it.

`crontab -e` uses vi by default. If you'd prefer to use a different editor, set
the
EDITOR environment variable. For example, to use emacs, in bash, type
`export EDITOR=emacs`.

You can have ranges of times and days. For example, putting '1-5' for the days
field will run the entry Monday through Friday. You can also have 'steps', so
that
certain days in the range are omitted. Putting '1-5/2' for the days will run the
entry Monday, Wednesday, and Friday, for example.


Written by Eric Warmenhoven warmenhoven@linux.com

--
☆ 来源:.BBS 荔园晨风站 bbs.szu.edu.cn.[FROM: bbs@202.104.99.66]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店