Linux: Crontab timing task commands

Source: Internet
Author: User
Tags crontab syntax

Linux: Crontab scheduled Task Command details 1. Crontab introduces the function of crontab command to schedule the execution of some commands at a certain interval. The 1.1/etc/crontab file has a crontab file under the/etc directory, which stores some scheduling programs that have been run systematically. Each user can create their own scheduling crontab. For example, [root @ dave ~] # Cat/etc/crontabSHELL =/bin/bashPATH =/sbin:/bin:/usr/sbin: /usr/binMAILTO = rootHOME =/# run-parts01 *** root run-parts/etc/cron. hourly02 4 *** root run-parts/etc/cron. daily22 4 ** 0 root run-parts/etc/cron. weekly42 4 1 ** root run-parts/etc/cron. monthly 1.2/etc/cron. deny and/etc/cron. allow file/etc/cron. deny indicates that the user/etc/cron cannot use the crontab command. allow indicates the user who can use crontab. If two files exist at the same time,/etc/cron. allow takes priority. If neither of the two files exists, only the Super User can schedule a job. Each user generates his/her own crontab file. These files are stored in the/var/spool/cron directory, for example, [root @ dave ~]. # Cd/var/spool/cron [root @ dave cron] # lsoracle root check the file directly. The content in the file is consistent with the crontab-l displayed by the corresponding user. [Root @ dave cron] # cat oracle00 6 ***/u02/scripts/del_st_archive.sh>/u02/scripts/del_st_arch.log 2> & 1 [root @ dave cron] # cat root0 12 */root/bin/sync-clock.sh [root @ dave cron] #2. crontab usage 2.1 Crontab syntax usage: crontab [-u user] file crontab [-u user] [-e |-l |-r] (default operation is replace, per 1003.2) -e (edit user's crontab)-l (list user's crontab)-r (delete user's crontab)-I (p Rompt before deleting user's crontab)-s (selinux context) where 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. Help: [root @ dave ~] # Man crontabCRONTAB (1) CRONTAB (1) NAME crontab-maintain crontab files for individual users (ISC Cron V4.1) SYNOPSIS crontab [-u user] file crontab [-u user] [-l |-r |-e] [-I] [-s] DESCRIPTION Crontab is the program used to install, deinstall or list the tables used to drive the cron (8) daemon in ISC Cron. each user can have their own crontab, and though these are files in/var/spool/, they are not intended to be edited directly. for SELinux in mls mode can be even more crontabs-for each range. for more see selinux (8 ). if the cron. allow file exists, then you must be listed therein order to be allowed to use this command. if the cron. allow file does not exist but the cron. deny file does exist, then you must not be listed in the cron. deny file in order to use this command. if neither of these files exists, only the super user will be allowed to use this command. OPTIONS-u It specifies the name of the user whose crontab is to be tweaked. if this option is not given, crontab examines "your" crontab, I. e ., the crontab of the person executing the command. note that su (8) can confuse crontab and that if you are running inside of su (8) you shoshould always use the-u option for safety too many s sake. the first form of this command is used to install a new crontab from some named file or standard input if the pseudo-filename "-" is given. -l The current crontab will be displayed on standard output. -r The current crontab will be removed. -e This option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. after you exit from the edi-tor, the modified crontab will be installed automatically. -I This option modifies the-r option to prompt the user for a temporary snapshot y/Y temporary snapshot response before actually removing the crontab. -s It will append the current SELinux security context string as an MLS_LEVEL setting to the crontab file before editing/replacement occurs-see the documentation of MLS_LEVEL in crontab (5 ). see also crontab (5), cron (8) FILES/etc/cron. allow/etc/cron. denySTANDARDS The crontab command conforms to IEEE Std1003.2-1992 (Signature (¡®Bytes ¡®POSIX has been written successfully ). this new command syntax differs from previous versions of Vixie Cron, as well as from the classic SVR3 syntax. diagnostics a fairly informative usage message appears if you run it with a bad command line. AUTHOR Paul Vixie <vixie@isc.org> 4th Berkeley Distribution 16 Januar 2007 CRONTAB (1) 2.2 Crontab format description we can use crontab-e to add the command to be executed. The command execution result, whether it is standard output or error output, will be sent to the user in the form of mail. The command to be added must be in the following format: *****/the first five fields of command path can take an integer to specify when to start working. The sixth field is a string, that is, a command field, the command includes the crontab scheduling command. The fields are separated by spaces and tabs. The first five fields represent: minute: 0-59 hours: 1-23 Date: 1-31 month: 1-12 weeks: 0-6 (0 indicates Sunday) you can also use some special symbols: *: to represent any time point,: To represent the split-: to represent a segment, for example, in the second end: 1-5, it indicates 1-5 points/n: indicates that each n is executed once. For example, in the second segment, */1 indicates that the command is executed every one hour. You can also enter 1-23/1. some examples: 00, 12, 16 */data/app/scripts/monitor/df. sh30 2 ***/data/app/scripts/hotbackup/hot_database_backup.sh10 8, 12, 16 ***/data/app/scripts/monitor/check_ind_unusable.sh10 8, 16 ***/data/app/scripts/monitor/check_maxfilesize.sh10 8, 12, 16 ***/data/app/scripts/monitor/check_objectsize.sh 43 21 *** run 15 05 *** run 0 17 *** run 0 17 *** 1 execute 0 at every Monday., 10 17 **, 3 every Sunday, Tuesday, and on Wednesday execute 0-10 17 1 ** 1 1 from to every 1 minute execute 0 0, * 1 1 and 15 and on the day execute on the first day of the month, execute 0 21 ** 1-6 Monday to Saturday execute, 20, 30, * 50 * execute at 10 */10 * execute at 10*1 * from to. Execute at every 1 minute. 0 */1*0: every 1 hour. Execute 0 ***** 0: every 1 hour. Execute 2 8-20/3,, execute 30 5, 15 *** on the 1st and 15th execute 2.3 & When running a job in the foreground, the terminal is occupied by the job. When running the job in the background, it does not occupy the terminal. You can run the job in the background using the & command. For example, 30 2 ***/data/app/scripts/hotbackup/hot_database_backup.sh & be careful when running jobs in the background: Do not run commands that require user interaction in the background, because this way, your machine will be waiting there. However, running a job in the background will output the result to the screen, interfering with your work. If a job running in the background produces a large amount of output, you 'd better use the following method to redirect its output to a file: command> out. file 2> & 1 & in this example, 2> & 1 indicates that all standard output and error output will be redirected to an out. file. 2.4 2> & 1 first look at an example: 0 2 ***/u01/test. sh>/dev/null 2> & 1 & this sentence means to execute this command in the background and redirect error output 2 to standard output 1, then put all the standard output 1 in the/dev/null file, that is, empty. Here there are several numbers: 0 indicates the keyboard input 1 indicates the standard output 2 indicates the error output. we can also write: 0 2 ***/u01/test. sh>/u01/out. file & -- not written here. The default value is 10 2 ***/u01/test. sh 1>/u01/out. file & 0 2 ***/u01/test. sh 2>/u01/out. file & 0 2 ***/u01/test. sh 2>/u01/out. file 2> & 1 & Change tesh. sh command output is redirected to out. file, that is, the output content is not printed to the screen, but to the out. file. 2> & 1 redirects the error output to the standard output. Then, redirect the standard input to the file out. file. & 1 indicates the description 1 of the file, indicating the standard output. If & is missing, it becomes the number 1, indicating redirection to file 1. &: Perform the test in the background: ls 2> 1: No error is reported without 2 files, but an empty file 1 is output; ls xxx 2> 1: if the file xxx does not exist, the error is output to 1. ls xxx 2> & 1: The file 1 is not generated, but the error is returned to the standard output; ls xxx> out.txt 2> & 1 = ls xxx 1> out.txt 2> & 1; because the redirection symbol> expiration is 1, the error output and standard output are all transmitted to the out.txt file. 2.5 2> & 1 is written in the following reason format: command> file 2> & 1 = command 1> file 2> & 1 first, command> file redirects the standard output to file, 2> & 1 indicates that a standard error is copied to the standard output, that is, the standard output and error are redirected to the file. If it is changed to command 2> & 1> file 2> & 1, the standard output is copied, but the standard output is still on the terminal.> The output is redirected to the file, but the standard error is still on the terminal.

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.