Linux crontab Timing Task command usage detailed

Source: Internet
Author: User
Tags command line linux

First, Crontab Introduction

The function of the crontab command is to schedule the execution of some commands at certain intervals.

1.1/etc/crontab file

In the/etc directory there is a crontab file, where there are some scheduling programs running on the system. Each user can establish their own scheduling crontab.

Such as:

[Root@dave ~]# Cat/etc/crontab

Shell=/bin/bash

Path=/sbin:/bin:/usr/sbin:/usr/bin

Mailto=root

home=/

# Run-parts

* * * * Root run-parts/etc/cron.hourly

4 * * * Root run-parts/etc/cron.daily

4 * * 0 root run-parts/etc/cron.weekly

4 1 * * Root run-parts/etc/cron.monthly

1.2/etc/cron.deny and/etc/cron.allow files

/etc/cron.deny represents a user who cannot use the crontab command

/etc/cron.allow represents a user who can use crontab.

If two files exist at the same time, then/etc/cron.allow first.

If two files do not exist, only a superuser can schedule the job.

Each user will generate a crontab file of their own. These files are in the/var/spool/cron directory:

Such as:

[Root@dave ~]# Cd/var/spool/cron

[Root@dave cron]# ls

Oracle Root

We look at the file directly and the contents are consistent with the crontab-l displayed by the corresponding user.

[Root@dave cron]# Cat Oracle

6 * * */u02/scripts/del_st_archive.sh >/u02/scripts/del_st_arch.log 2>&1

[Root@dave cron]# Cat Root

0 * * * */root/bin/sync-clock.sh

[Root@dave cron]#

Second, Crontab use instructions

2.1 Crontab Grammar

Usage:crontab [-u user] File

crontab [-u user] [-e |-l |-r]

(default operation is replace, per 1003.2)

-E (Edit user ' s crontab)

-L (list user ' s crontab)

-R (Delete user ' s crontab)

-I (Prompt before deleting user ' s crontab)

-S (selinux context)

Where file is the name of the command file. If the file is specified on the command line, then the crontab command is executed, and the file is copied to the Crontabs directory, and if the file is not made on the command line, the crontab command accepts the command typed on the standard input (keyboard). And they are also stored in the crontab directory.

Help:

[Root@dave ~]# Mans crontab

CRONTAB (1) CRONTAB (1)

NAME

Crontab-maintain crontab files for individual users (ISC Cron V4.1)

Synopsis

crontab [-u user] File

crontab [-u user] [-l |-r |-e] [-i] [-s]

DESCRIPTION

Crontab is the program used to install, deinstall or list of the tables used to drive the cron (8) daemon in ISC cron. Each user can have their own crontab, and though this are files in/var/spool/, they are not intended to be edited D irectly.  For SELinux in MLS mode can is even more crontabs-for each range. For more SELinux (8).

If The Cron.allow file exists, then you must is listed the to the "to" to "use" this command. If The Cron.allow file does not exist but the Cron.deny file does exist, then you must don't be listed in the CR  The On.deny file in order to use this command. If Neither of these files exists, only the "super" user would be allowed to use this command.

OPTIONS

-U It Specifies the name of the user whose crontab is tweaked.  If This option is not given, Crontab examines "your" crontab, i.e., the crontab of the person executing the command. Note that SU (8) can confuse crontab and this if you are running inside to SU (8) You should always use the-  U option for safety?ˉs sake. The "This" is "used to install a" new crontab from some named file or standard input if th E Pseudo-filename "-" is given.

-L The current crontab is displayed on standard output.

-R The current crontab would be removed.

E-This option is used to edit the current crontab using the editor specified by the VISUAL or editor environment VA  Riables. After your exit from the Edi-tor, the modified crontab would be installed automatically.

I-option modifies the-r option to prompt the user for a? ˉy/y?ˉresponse before actually removing the crontab .

-S It'll append the current SELinux security context string as a mls_level setting to the crontab file before Editing/replacement Occurs-see The documentation of Mls_level in Crontab (5).

ALSO

Crontab (5), cron (8)

FILES

/etc/cron.allow

/etc/cron.deny

Standards

This article URL address: http://www.bianceng.cn/OS/Linux/201410/45488.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.