Linux Task Scheduler

Source: Internet
Author: User

  1. Linux Task Scheduler:

    1. One-time task execution (at, batch);
      1. At: A timed task that specifies a time to perform a task that can only be performed once.
        1. At the mode of use;
            1. Interactive: Let the user enter multiple commands to execute at the at> prompt;
            2. Batch processing: Writes a command of a task to a file to be called by at;
        2. at command use;
            1. at [parameter] [TIME]
            2. At> COMMAND
            3. At> Ctrl+d
        3. At time: defines when the at task is to be carried out;
          1. HH:MM: At today's hh:mm time, if that moment is over, tomorrow's hh:mm will do this task.
              • Ex> 04:00
          2. hh:mm YYYY-MM-DD: Specifies that the task should be carried out at a particular time of day of the month of the year
              • Ex> 04:00 2009-03-17
          3. HH:MM[AM|PM] [month] [Date]: Specifies that the task should be carried out at some point in the month of the year
              • Ex> 04pm March 17
          4. HH:MM[AM|PM] + number [Minutes|hours|days|weeks]: Specifies how much time will be added to the task at a certain point in time
              • Ex> now + 5 minutes
              • Ex> 04pm + 3 days
          5. time format extension:at allows you to use a fairly complex set of time-specific methods.
              1. Be able to accept the time specified in the hh:mm (Hours: minutes) of the day. If the time has passed, then it will be executed the next day.
              2. Can use Midnight (late night), noon (noon), Teatime (tea time, usually 4 o'clock in the afternoon) and other vague words to specify the time.
              3. Be able to use the 12-hour timekeeping system, that is, after the time plus AM (morning) or PM (afternoon) to indicate whether it is morning or afternoon.
              4. Ability to specify a specific date for the execution of the command, specifying the format for Month Day (month) or mm/dd/yy (Month/day/year) or Dd.mm.yy (day. Month), the specified date must be followed by the specified time.
              5. Be able to use relative timing method. The specified format is: Now + Count Time-units, today is the current time, Time-units is the time unit, here can be minutes (minutes), hours (hours), Days (day), Weeks (week). Count is the amount of time, days, hours.
              6. The ability to specify the time to complete a command directly using today (present), Tomorrow (Tomorrow).
        4. at common parameters;
            1. -M: When the specified task is completed, the user will be sent a message, even if there is no standard output;
            2. Alias of-I:ATQ;
            3. Alias of-D:ATRM;
            4. -V: Shows when the task will be executed;
            5. -C: Print the contents of the task to the standard output;
            6. -V: Displays version information;
            7. -Q: Add < queue after > use specified queue;
            8. -F: Add < file > read from specified file instead of reading from standard input;
            9. -T: Back < time parameters > submit the task to be run in the form of a time parameter;
        5. at permission control file;
            1. /etc/at.allow
            2. /etc/at.deny
            3. Control file usage rules;
              1. First find/etc/at.allow This file, written in this file users can use at, no user in this file can not use at (even if not written in At.deny);
              2. If the/etc/at.allow does not exist, look for/etc/at.deny this file, if the user written in this at.deny can not use at, but not in this At.deny file users will be able to use the AT command.
              3. If none of the two files exist, then only root can use the AT command.
              4. In general distributions, because it is assumed that all users on the system are trustworthy, the system usually retains an empty/etc/at.deny file, meaning that all people are allowed to use the AT command.
              5. If you don't want some users to use at, write the user's account to/etc/at.deny! One account to write a line.
        6. At points of attention;
            1. If the AT command output path is incorrect, the result will be sent to the user in the form of mail
            2. When a task is created, it is assigned to a task number and is queued in/var/spool/at. It is not recommended to use VI Editor to modify, error-prone.
      2. Batch: The same commands are executed regularly with at, but the difference is that batch does not require a specified time because it is automatically executed when the system load is low (the average load is less than 0.8);
    2. Periodic task Execution (crontab, Anacron);
      1. Crond introduction;
        1. Crond is a daemon that is used to periodically perform certain tasks or wait for certain events under Linux, similar to Scheduled tasks under Windows, when the operating system is installed, the Service tool is installed by default and the Crond process is started automatically. The Crond process periodically checks to see if there is a task to perform, and if there is a task to perform, the task is automatically performed;
        2. crontab task scheduling;
            1. System task scheduling: The work to be performed by the system periodically, such as writing cache data to hard disk, log cleanup, etc.
              • /etc/crontab
              • Minutes Hours Day Month Week user tasks
            2. User Task scheduling: Users to perform regular work, such as user data backup, scheduled email reminders and so on. Users can use the Crontab tool to customize their own scheduled tasks. /var/spool/cron/username, whose file name is the same as the user name;
              • /var/spool/cron/username
              • Minutes Hours Day Month Week user tasks
        3. Cron user privileges;
            1. /etc/cron.deny: The user listed in the file is not allowed to use the crontab command;
            2. /etc/cron.allow: The users listed in the file are allowed to use the crontab command;
            3. /var/spool/cron/: The directory where all user crontab files are stored, named after the user name;
        4. Cron time valid value;
            1. Minutes: 0-59;
            2. Hours: 0-23;
            3. Days: 1-31;
            4. Month: 1-12;
            5. Week: 0-7,0 and 7 both indicated Sunday;
        5. Cron time wildcard representation;
            1. *: All valid values for the corresponding time;
        6. ,: discrete point of time;
              1. 10,40 * * 2,5 Week 2 and Week 5 perform a scheduled task at 2:10 and 40
            1. -: continuous point of time;
              1. * * 1-5 Monday to Friday 2:10 perform a scheduled task
            2. /#: How often in the corresponding value range
              1. */3 * * * * * perform tasks every three minutes
              2. */3 * * * */bin/cat/etc/fstab &>/dev/null view/etc/fstab files every three minutes, execution results are not sent to administrators in the form of messages
      2. Crontab
          1. Command format:
            1. crontab [-u user] File
            2. crontab [-u user] [-e |-l |-r]
          2. Common parameters:
            1. -E: Edits the contents of a user's crontab file. If the user is not specified, the crontab file of the current user is edited;
            2. -L: Displays the contents of a user's crontab file, or displays the contents of the current user's crontab file if no user is specified;
            3. -r: Deletes a user's crontab file from the/var/spool/cron directory and, if no user is specified, deletes the current user's crontab file by default;
            4. -I: give confirmation prompt when deleting user's crontab file;
            5. -U USERNAME: Managing cron tasks for its users
              • [Email protected] ~]# crontab-u hadoop-e
              • Crontab:installing New Crontab
              • [Email protected] ~]$ crontab-l
              • 1,3,5 * */bin/echo Hello
          3. precautions;
            1. If% is used in the crontab user command, it is escaped to \%;
              • 5 3 * * */bin/touch ~/testfile_ ' date +\%y-\%m-\%d '. txt
            2. After using single quotation marks,% can also not be escaped;
              • 5 3 * * */bin/touch ~/testfile_ ' date + '%y-%m-%d '. txt
      3. Anacron: is a crontab supplement, used to check whether a task in the crontab has not been executed in the past period, if not executed, it will be executed at some point after the boot, regardless of whether its cycle arrives;

Linux Task Scheduler

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.