Shell-crontab quick Manual

Source: Internet
Author: User
Tags crontab example
This article is based on the following English documents: http://www.adminschoice.com/docs/crontab.htm.
Cron is a UNIX tool that uses cron background processes to automatically execute tasks at a specific time in the future. These tasks are usually called cron jobs. crontab, which is a Cron record to be run at a specific time.
1. crontab restrictions:
If your name appears in/usr/lib/cron. allow, You can execute crontab. if the file does not exist, and your name is not in/usr/lib/cron. deny appears. You can also use crontab. if only cron. deny exists and is an empty file, so all users can use crontab. if both files do not exist, only root users can use crontab. one user name per line of the All/deny file.
2. crontab command:
First, you must specify an editor to open the crontab file.
Crontab-E: edit your crontab file or create one if it does not exist.
Crontab-L: displays your crontab file.
Crontab-R: delete your crontab file.
3. crontab File Syntax:
* *** Command to be executed
-----
|
| + ----- Day of week (0-6) (Sunday = 0)
| + ------- Month (1-12)
| + --------- Day of month (1-31)
| + ----------- Hour (0-23)
+ ------------- Min (0-59)
* In the value field above indicates all valid values in the column brackets. The value column can be a * or a group of elements separated by commas. The elements of all columns are either a number in the preceding range or two numbers in the preceding range separated by the delimiter (-) (representing a left-right closed domain ).
Date can be specified in two domains: Month day and week day. If both are specified in one record, they are the cumulative effect of the two records.
  4. crontab example
In the following crontab file, a column is removed from/home/someuser/tmp:
30 18 * RM/home/someuser/tmp /*
Changing the parameters will make the Command run according to different time plans as follows:
Min Hour Day/month Month Day/week Execution time
30 0 1 1, 6, 12 * Executed at on July 22, and July 1
0 20 * 10 1-5 Of every workday (Monday to Friday) in February
0 0 1, 10, 15 * * Execute at midnight on the day 1, 10, and 15 of each month
5, 10 0 10 * 1 Run the command at and on every Monday and the 10th of every month.

5.Crontab Environment
Cron uses/usr/bin/sh to call the command from the user's home directory.
Cron provides a default environment for each shell, which is defined as follows:
Home = user's-home-directory
LOGNAME = user's-login-ID
Path =/usr/bin:/usr/sbin :.
Shell =/usr/bin/sh
If the user wants their. if profile is executed, it must be explicitly executed in the crontab command script, or in a separate script, it is called by the crontab command script.
6.Disable email
The information output to the screen under the command line will be written to mail when crontab is used. If not, place the following command at the end of crontab's cron job line.
Note: When running a program with>/dev/null on UNIX, the output from the program to stdout can be blocked. However, if the program also outputs to stderr, the information output to stderr is still displayed on the screen. A common method to shield stderr is to use pipelines to output stderr to stdout and stdout to/dev/null. It is generally written as follows: Proc>/dev/null 2> & 1. this method is only applicable to the sh environment. If it is in another shell environment, such as CSH, "ambiguous output redirect.. Fortunately, the default shell of crontab is sh.
7.Generate log files
As with Principle 6, you can just redirect it to a file:
>/Home/someuser/cronlogs/a. log 2> & 1


Related Article

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.