Linux shell programming Notes-Background execution command crontab__ block chain

Source: Internet
Author: User

The Backstage execution command, is puts the shell command to the system backstage to execute, does not display in the terminal, does not affect the user to continue to work in the terminal, even if the terminal closes the command also to execute.

Noun Explanation:

1), cron system scheduling process, 2, at at command, running special jobs at specific times, 3, & running a process in the background that is not long, 4, Nohup running a command in the background, even if the user exits and is not subject to shadow Ring. 1, crontab command:

Crontab command, which is used to perform shell jobs on a regular basis. Crontab submits a job to a cron process in the form of a crontab file.

The crontab command executes the job periodically.

Root users can disable and enable users to have their own crontab files by using the Cron.deny and Cron.allow in the/etc directory.

2, crontab domain Description:

1th minute 1~59 2nd hour 1~23 (0 for midnight) 3rd Liege 1~31 4th 1~12 5th List Week 0~6 (0 for Sunday) 6th column to run the command (can be she ll command, can also be a shell script file 3, crontab format:

Minutes <> <> Day <> month <> Week <> the command to run #<> represents a space

Description

1, if a time domain, with the * instead, the description is any number, 2, if a time domain, to fill in multiple numbers, can be separated by commas, 3, if a time domain, to fill out a continuous time, you can pass-delimited; instance:

    * * * * */apps/bin/cleanup.sh    #每天晚上21:30 Execute cleanup.sh This shell script under the/apps/bin directory;
    1 * * 6,0/bin/find-name "core" -exec rm {} \;    #每周六, Sunday 1:10 Execute Find command to locate files and delete files;
    0,30 18-23 * * * */apps/bin/dbcheck.sh    #每天18:00~23:00, execute shell script every 30 minutes;
Precautions:
1, submit jobs to cron, execute shell script files, use absolute directory to specify Shell script files, 2, shell script, use environment need to be defined in the shell, 3, before you submit a job to Cron, configure the editor environment variable,         The goal is to let the cron process know what editor to use to execute the crontab file. Edit the. Profile file (Gedit ~/.profile) in the user $home directory and add the following: Editor=vi; Export EDITOR 4. Create a new crontab file:

1) Touch Cbcron 2) gedit Cbcron #加入以下内容

# echo something to file every minutes between 5,10,15,20,25,30,35,40,45,50,55
14-18 * */bin/echo ' hel L cb! ' >>/home/cb/documents/cbhello
3) submitted Crontab:crontab Cbcron 4) List crontab:crontab-l 6) Backup crontab:crontab-l > $HOME/mycron #把cronta b Backup to the user root directory of the Mycron file; 5. Edit crontab File:
CRONTAB-E #系统会用设置好的EDITOR环境变量指定的编辑器打开crontab;

6, delete the crontab file:

Crontab-r

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.