Use shell scripts to schedule tasks

Source: Internet
Author: User
Execute scheduled tasks using shell scripts. 1. execute multiple tasks concurrently without affecting each other. use the lock mechanism to avoid overlapping execution of a single task. 2. each task is saved as a separate script and is independent of each other. 3. the start running time is supported, for example, & quot; 2013/05/08 & quot ;,... execute scheduled tasks using shell scripts. 1. execute multiple tasks concurrently without affecting each other. use the lock mechanism to avoid overlapping execution of a single task. 2. each task is saved as a separate script and is independent of each other. 3. the start time is supported, for example, "", "", or "now ". You can also modify the value of the start running time. for example, "now + 5 m" indicates that the value is executed after 5 minutes of the current running time (a negative correction value is also implemented, for example,-1 h, I think this function is boring now ). 4. multiple types of operation cycle settings are supported, including seconds, minutes, hours, days, weeks, months, and years. 5. the sleep time is automatically set based on the task execution interval, and the main program occupies a very small amount of resources. 6. a task can be a SHELL script or a linux command. 7. an independent task configuration file that centrally defines the task content, start time, and run interval. (More intuitive than crontab settings) 8. supports reload task configuration files during runtime. you can add the adjusted tasks to the plan without restarting the main program. 2. description of the task configuration file: the default task configuration file corresponds to a scheduled task in each line of mytask. conf under the main program directory. the configuration items are separated by commas. The task configuration is defined as follows: <任务内容> , <起始运行时间> , <运行周期> 1. The task content can be script files and commands. Note that you can use the global variable $ BASEDIR to indicate the Directory of the main program. We recommend that you save complex commands in a script file. 2. the start running time is divided into two parts. The first part is the initial time in the format of "yyyy/MM/dd hh: mm: ss". It can also be a time value segment, for example: "", "03/05", "03/05", "", "", or the current time "now ". The second part is the correction time, in the format of "+ time unit" or "-time unit", which means further time correction based on the initial time. For example, "+ 5 s" and "-10 m. The unit of time is case-sensitive. the specific definitions are as follows: y = year, M = month, d = day, h = hour, m = minute, s = second, w = Week 3. the running cycle is the interval of running the task function, the value is similar to the correction time, but the +-sign is canceled. if the value is 0 without unit, the operation is only performed once. The task definition example is as follows: # run the task at a.m. and run the task once every one day. $ BASEDIR/tasks/backdb. sh, 1d # run every one month after 2 minutes of the current time. $ BASEDIR/tasks/test1.sh, now + 2 m, 1 M # run at, January 1, May 12 every 1 hour. /Home/lykyl/sp. sh, 5/12, 1 h # starts execution at and runs every 30 seconds. $ BASEDIR/tasks/test3.sh, 30 s # The task is started and runs every 1 minute. Touch/tmp/ohyeah, now, 1 m # run the task only once after 1 hour of the current time. $ BASEDIR/tasks/test5.sh, now + 1 h, 0 3. program Control Command 1. start nohup. /mytask. sh & 2. exit kill-15 'cat. /mytask. pid '3. reload the task configuration file kill-SIGUSR1 'cat. /mytask. pid'
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.