How to use Crontab in CentOS

Source: Internet
Author: User
The crontab service requires root permissions. The following is an official explanation: SHELL =/bin/bashPATH =/sbin:/bin:/usr/sbin: /usr/binMAILTO = rootHOME =/# Fordetailsseeman4crontabs # Exampleofjobdefinition:

The crontab service requires the root permission for execution.

The following is an official explanation:

SHELL =/bin/bash
PATH =/sbin:/bin:/usr/sbin:/usr/bin
MAILTO = root
HOME =/


# For details see man 4 crontabs


# Example of job definition:
#. ---------------- Minute (0-59)
# |. ----------- Hour (0-23)
# |. ---------- Day of month (1-31)
# |. ------- Month (1-12) OR jan, feb, mar, apr...
# |. ---- Day of week (0-6) (Sunday = 0 or 7) OR sun, mon, tue, wed, thu, fri, sat
# |
# ***** User-name command to be executed

The usage is as follows:

New scheduling task

Run the crontab-e command to edit the scheduled task to be executed. you can also edit the content in the/etc/crontab file. The example is as follows: ceshi in this example. sh is the script stored in the/root directory.

* ***/Root/ceshi. sh: execute ceshi. sh once per second

30 5 ***/root/ceshi. sh execute ceshi. sh at 05:30 every day

** 1 1 */root/ceshi. sh: execute ceshi. sh every month on January 1, January 1.

30 5 */10 ** root/ceshi. sh run ceshi. sh at 05:30 every 10 days.

30 5 ** 1/root/ceshi. sh run ceshi. sh every Monday 05:30

View scheduled tasks

Run: crontab-l

Delete a scheduling task

Run: crontab-r

Save the output result of the scheduling task

Add>/path/file 2> & 1 after the task

For example

30 5 */10 ** root/ceshi. sh>/root/record.txt 2> & 1

Note: 2> & 1 redirects all execution results to the target file.

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.