Linux scheduled execution command crontab

Source: Internet
Author: User
Syntax: crontab [-e [UserName] |-l [UserName] |-r [UserName] |-v [UserName] | File] description: crontab is used to allow users to run programs at a fixed time or interval. In other words, it is similar to the user's time table. -U...

Syntax: crontab [-e [UserName] |-l [UserName] |-r [UserName] |-v [UserName] | File]
Note: crontab is used to allow users to execute programs at a fixed time or interval. In other words, it is similar to the user's time table. -U user is used to set the time table of the specified user. The premise is that you must have the permission (for example, root) to specify the time table of another user. If-u user is not used, the time table is set.
Parameters:
-E [UserName]: run the text editor to set the time table. the preset text editor is VI. if you want to use another text editor, set the VISUAL environment variable to specify the file to use.
-R [UserName]: deletes the current time table.
-L [UserName]: list the current time series table
-V [UserName]: lists the statuses of user cron jobs.
Usage:
A B c d e program
A indicates the minute, B indicates the hour, c indicates the day of the month, d indicates the month, and e indicates the day of the week. Program indicates the program to be executed.
If expression a is *, the program is executed every minute. if expression B is *, the program is executed every hour, and so on.
When a is a A1-B2, it indicates execution from a1 to a2 minutes, B indicates execution from b1 to b2 hours, and so on
When a is */n, the execution is performed every n minutes. if B is */n, the execution is performed every n hours.
When a is a1, a2, a3 ,... a1, a2, a3 ,... execute in minutes. B is b1, b2, b3 ,... b1, b2, b3... 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.
Example:
0 */2 ***/usr/local/test. sh
The command line indicates that the test. sh script is executed every two hours.
0 9 ** 1/usr/local/test. sh
This command indicates that the program is executed every Monday. if you change 0 to *, the program is executed every minute from to. (0-6) indicates the number of weeks, 0 indicates Sunday, and 6 indicates Saturday.
If automatic execution is set and you want to check whether the program is executed, you can view the log:
Tail-f/var/log/cron
 
List crontab file content
To list crontab files, you can use: $ crontab-l
Edit the crontab file
If you want to add, delete, or edit entries in the crontab file, and set the EDITOR environment variable to vi, you can use vi to edit the crontab file. the corresponding command is:
$ Crontab-e
You can modify the crontab file and exit as if you were using vi to edit any other files.
Delete a crontab file
To delete the crontab file, you can use: $ crontab-r.
Restore the lost crontab file
If you accidentally delete the crontab file by mistake, if you have a backup in your $ HOME directory, you can copy it to/var/spool/cron/ , Where Is the user name. If the copy cannot be completed due to permission issues, you can use: $ crontab Where, Is the file name of your copy in the $ HOME directory.

This article is from "My food is here"

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.