Set the Linux scheduled Run Command Script (crontab details)

Source: Internet
Author: User
Boyun was published on 1. Log On with the root permission
2. crontab-u lsbi-e
3. Add the command to be started, such as 40 4 18 **/oracle_backup/bin/scott_select.sh
4. Restart service crond restart
5. OK

Note:
1. The program to run in cmd is sent to SH for execution. This shell only contains three environment variables: User, home, and shell.
2. Set each fraction to the */5 *** cmd command.

The following is an example file:
# Min hour day month dayofweek command
# Every morning
106 *** date

# Every two hours
0 */2 * Date

# Every two hours from PM to AM.
0 23-7/2, 8 **** date

# Am on the 4th day of each month and from Monday to Wednesday of each week
0 11 4 * Mon-wed date

# A.m. of July
0 4 1 Jan * Date
Example
Lark: ~> The crontab-1 lists the current crontab of the user.
# Min hour day month dayofweek command
10 6 **** date
0 */2 * Date
0 23-7/2, 8 **** date

Make a script run automatically and periodically,
[Root @ test1 init. d] # crontab-e
Add a line after the root file (meaning: Execute scott_select.sh at on the 18 th of each month)
40 4 18 **/oracle_backup/bin/scott_select.sh
0 0 23 **/patch to tranferfiles. Sh>; tranferfiles. Log
Do not forget to start the scheduled service after the settings are complete (most of them forget this)
[Root @ test1 init. d] # service crond stop
[Root @ test1 init. d] # service crond start
Or
/Etc/init. d/crontab start

Note:
The crontab command schedules the execution of some commands at certain intervals. There is a crontab file in the/etc directory, which stores some scheduling programs that are running systematically (and cron. d/cron. deny cron. Monthly/cron. Weekly/
Cron. daily/cron. Hourly/crontab ). Each user can create their own scheduling crontab (/var/spool/cron each user's file is named crontab-u someone-E ).
The crontab command has three forms of command line structure:
Crontab [-u user]
Crontab [-u user] [-E |-L |-R]
Crontab-l-u [-E |-L |-R]
In the first command line, file is the name of the command file. If this file is specified in the command line, run the crontab command to copy the file to the crontabs directory. If this file is not specified in the command line, the crontab command will accept the commands typed on the standard input (keyboard) and store them in the crontab directory.
In the command line, the-r option is used to delete the crontab file from the/var/spool/cron/crontabs directory;
In the command line, the-L option is used to display the contents of the crontab file.
Run the crontab-u user-e command to edit the cron (c) job of the user. You can edit a file to add or modify any
Business request.
Run the crontab-u user-R command to delete all cron jobs of the current user.
Jobs and their scheduled time are stored in the file/var/spool/cron/crontabs/username. Username:
The command that the user wants to run is stored in the file. The command execution result, whether it is standard output or error output, will be sent to the user in the form of mail. Each request in the file must contain six fields separated by spaces and tabs. The first five fields can take an integer to specify when to start working. The sixth field is a string called a command field, which includes the crontab command for scheduling and execution.
The value range and significance of the integer in the first and fifth fields are as follows:
0 ~ 59 indicates the score
1 ~ 23 indicates the hour
1 ~ 31 indicates the day
1 ~ 12 indicates the month.
0 ~ 6 indicates the week (0 indicates Sunday)
/Usr/lib/cron. allow indicates who can use the crontab command. If it is an empty file, it indicates that no user can schedule
Industry. If this file does not exist and another file/usr/lib/cron. deny exists, only
Users can use the crontab command. If it is an empty file, it indicates that any user can arrange jobs. When two files exist simultaneously
Cron. allow takes precedence. If none of them exist, only super users can arrange jobs.

 

 

 

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.