Introduction to crontab in AIX and Linux

Source: Internet
Author: User

In AIX and Linux, crontab introduces similar crontab usage in AIX and Linux. First, it introduces Crontab usage in Linux, and then introduces differences between AIX and Linux. 1. Crontab the crontab command is used 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 instructions 2.2 Crontab format instructions 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: ***/command_path can take integer values for the first five fields, specifying 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: "*": represents any time point ",": represents segmentation "-": represents a segment, such as in the second end: 1-5, 1 to 5 "/n": indicates that each n unit 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 on Monday 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> & 1 is written in the following 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> file2> & 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. Cron background process # service crond status 3. Differences from AIX: the crontab file will be placed in the/var/spool/cron/crontabs AXI without */3 format. It can only be 1, 3, 5, 7, 9.

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.