Crontab writing in linux and precautions

Source: Internet
Author: User
For details about how to write crontab in linux, refer to Linux general technology-Linux programming and kernel information. Author: doomhuntercj

Crontab filecrontab [-u user] [-u user] {-l |-r |-e}

Statement:
F1 f2 f3 f4 f5 program

F1 indicates the minute, f2 indicates the hour, f3 indicates the day of the month, f4 indicates the month, and f5 indicates the day of the week. Program indicates the program to be executed.

When f1 is *, the program is executed every minute, when f2 is *, the program is executed every hour, and so on.

When f1 is a-B, it indicates that execution is performed from the minute a to the minute B. When f2 is a-B, it indicates that execution is performed from the hour a to the hour B, other analogy

When f1 is */n, the execution is performed every n minutes. If f2 is */n, the execution is performed every n hours.

When f1 is a, B, c ,... a, B, c ,... execute in minutes. f2 is a, B, c ,... a, B, c... execute in hours, and so on

You can also store all settings in the file first, and use crontab file to set the time table.

Special notes:
Many of my friends write crontab results that cannot be run for the following two reasons:

1. Path: the path for executing shell scripts. The path executed in crontab is not the path of your shell script. Note the writing method, for example, run. sh, written in/home/alex with the following content:

#! /Bin/sh
Java-cp/opt/lib/commons-logging.jar: news. jar com. mangken. NewsCrawl

The new. jar file is written in/home/alex and must be changed to the absolute path.

2. In the execution environment, many of my friends complained that why can't I use crontab to execute shell statements that are executed manually? Even though some functions and methods are not executed, the execution environment is different from the crontab execution environment, crontab is a new shell in which the shell will not load your profile. You need to re-load the environment variable before running. The method is to add the user identity when writing the shell.

* *** Su-user-c 'your. shell'

Example: */30 * su-root-c '/home/alex/run. Sh'

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.