Linux Task Plan detailed

Source: Internet
Author: User

Linux Task Scheduler, recurring task execution

One task at a time in the future: At,batch periodically runs a task: crontab execution Result: It will be sent to the user via email.
Mail easy to use
Check to see if your local email service is turned on         ~]$ netstat -tnlp     ~]$ ss -tnl     Make sure  127.0.0.1:25  is in the listening state. Local e-mail service:     smtp:simple mail transmission proticol    pop3:post office  procotol    imap4:internet mail access procotolmail Command:     mailx - send and receive Internet mail         mua:mail user agent Mail User agent: The user to send and receive mail the tool program     mailx [-s  ' Subject '] username[@hostname generation of]     message body:          (1) interactive input;. A single row can represent the end of the body, ctrl+d submissions can also be         ~]# mail -s   ' Hello ci '               ci         hi        .         EOT        [[email protected] ~]#           (2) via input redirection;          mail ci < /etc/fstab         (3) through the pipe;             cat /etc/fstab |mail -s  ' Fstab  file '  ci
AT command
AT&NBSP;[OPTION]...&NBSP;TIME&NBSP;&NBSP;&NBSP;&NBSP;TIME:&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;HH: Mm[yyyy-mm-dd]        noon (12 O'Clock Noon), Midnight (12 O'Clock Midnight), teatime (four o'clock in the afternoon), tomorrow        now+#             UNIT:minutes,hours,days,OR weeks                 [[email protected] ~]$ at now+2min                 at> cat  /etc/fstab                 at> <EOT>                 job 2 at 2016-08-16 10:16                 [[email protected] ~]$ at -l                 2       2016-08-16  10:16 a ci                 [[email protected] ~]$      at's job has a queue, denoted by a single letter, by default using the A queue common option:     -l:at -l =atq  View the queue of pending executions that were previously submitted, execution complete disappears   at -f  At.tasks now+5min  -f /path/from/somefile: Reads the job task from the specified file without having to enter it interactively; a command for a line of content in a file    at -d 3  Delete a job with the specified job number     at -d 3 = atrm 3   at -c : View specific contents of a specified job   -q queue: Indicate queue note: Job execution results are sent to the user who submitted the job by mail
Batch command:
Batch gives the system the option to perform the specified task at a time when the system resources are idle
Recurring Task Scheduler Cron

Cron Introduction

Service Program:     cronle Package: Main package, provides Crond daemon and related auxiliary tools, make sure Crond daemon (daemon) is running      centos 7:        systemctl status crond.service         active:active (running)                  CentOS 6:         service crond status              ...is running Note: Submitting a job to Crond is different from at, it requires a dedicated configuration file with a fixed format, and it is not recommended to edit the file directly using a text editor. To use the crontab command, Crontab prompts for syntax errors, and cron tasks fall into two categories      system cron tasks: As long as they are used to implement the system's own maintenance;           Manual editing:/etc/crontab file            This kind of task basically does not use the user self-modification      user cron Task:         command: crontab command Configuration format for      system crontab &NBsp;                    # example of job definition:        # &NBSP:---------------- minute  (0 - 59)         # &NBSP;|&NBSP;&NBSP:------------- hour  (0 - 23)         &NBSP;#&NBSP;|&NBSP;&NBSP;|&NBSP;&NBSP:---------- day of month  (1 - 31)          # |  |  | &nbsp.------- month   (1&NBSP;-&NBSP;12)  OR jan,feb,mar,apr ...         # |  |  |  | &nbsp---- day of week  (0 -  6)   (sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat         # |  |  |  |  |        # *   *  *  *  * user-name command to be executed          Note:              (1) Each row defines a recurring task, a total of 7 fields;                   *  *  *  *  *: Define recurring time                     User-name: User identity for running tasks                    command to be executed: Quests               (2) The environment variable here differs from the environment that is obtained after the user logs on, so it is recommended that the command use an absolute path, or a custom path environment variable.              (3) Execution result message sent to mailto specified user      user cron configuration format:/var/spool/cron/username         shell=/bin/bash        path=/sbin:/bin:/usr/ sbin:/usr/bin        mailto=root         HOME=/                 # For details see man 4 crontabs                 # Example of job definition:  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;#&NBSP:---------------- minute  (0 - 59)          # | &nbsp------------- hour  (0 - 23)         # |  | &nbsp.---------- day of  month  (1 - 31)         # |  |  |  .--- ---- month  (1 - 12)  OR jan,feb,mar,apr ...         # |  |  |  | &nbsp.---- day of week   (0 - 6)   (sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat         # |  |  |  |  |         # *  *  *  *  *  user-name command to be executed       Note:          (1) Each row defines a cron task, a total of 6 fields          (2) The environment variable here differs from the environment that is obtained after the user logs on, so it is recommended that the command use an absolute path or a custom path environment variable.          (3) mail is sent to the current user

time notation:

(1) A specific value:     a value in the range of valid values for a given point in time;         Note: day or  week  and  day of month  are not used at the same time; (2) *     all values in the range of valid values at a given point in time; table "per" (3) A discrete value at a specified point in time:     multiple values separated by commas at a given point in time;     #,#,# (4) successive values:-      use at point-link start and End     #-# (5) at a specified point in time, define the step size:/#: #即步长     */2      Note:         (1) when the specified point in time cannot be divisible by stride length, its meaning will no longer exist;          (2) The minimum time unit is "minutes", want to complete the second level of program tasks, need to use additional mechanisms               is defined as a per-minute task: The loop executes multiple times per minute with the script implementation; Example: (1) 3 * * * *  : Hourly, 3 minutes per hour (2) 3 4 * * 5: Executed once a week, every Friday 4:3; (3) 5 6 7 * *  : 7th per month 6:5 (4) 7 8 9 10 *: Every year, October 9 8:7; (5) 9 8 * *  3, 7:8:9 (6) 0 8,20 *  per Wednesday and Sunday* 3,7:8 points and 20 points per Wednesday and Sunday (7) 0 9-18 * * 1-5 : Working hours Monday to Friday from 9 to 18, once per hour (8) */5 *  * * * : Perform a task once every 5 minutes (9) 77
Usage of the crontab command
crontab [-u user] [-l |-r |-e] [-i] [-s]-e: Edit task;-L: List All Tasks-r: Remove all Tasks; Delete/var/spool/cron/username file-I: Using the-R option to remove all tasks, remind the user to confirm-u user:root user can manage cron tasks for specified users note: The results of the operation are notified to the current user by mail, if the mail is rejected; (1) command >/dev/null (2) Command & amp;>/dev/null Note: When you define a command, you need to escape it if it needs to use%. But the percent placed in single quotation marks is not escaped;

Thinking: A task at a specified time because the shutdown does not suffocate, the next opportunity will not be automatically executed?

No, if you expect a certain time due to failure to execute, the next time after the boot, whether or not the corresponding point should be executed once, you can use Anacron implementation;

Practice:

1. Back up the/etc directory every 12 hours to the/backup directory, save the file name in the format "ETC-YYYY-MM-DD-HH.TAR.XZ" 2.2,4,7 a weekly backup/var/log/secure file to/logs directory with the file format " Secure-yyyymmdd ' 3. Take out every two hours. The line information in the/proc/meminfo file that starts with S or M is appended to the/tmp/meminfo.txt;

This article is from "vinegar with soy sauce bottles" blog, please be sure to keep this source http://sauce.blog.51cto.com/11880696/1839344

Detailed Linux task plan

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.