20150905 Linux Task Scheduler

Source: Internet
Author: User

    • Task Scheduler

Perform a task at a time in a future point At,batch

To perform a task periodically: crontab

The at and Crontab implementations are sent to the system by mail Service

At present the system each user has the mail address, the mail service will launch the port SS-TNL

For 127.0.0.1:25, can only give the machine itself

650) this.width=650; "title=" clip_image001 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image001 "src=" http://s3.51cto.com/wyfs02/M00/72/BE/ Wkiol1xsbbzbqljtaaa1q9d3nm8987.jpg "width=" 371 "height="/>

    • e-Mail Service:

Defined:

SMTP:SIMLE Mail transmision Protocol message sent

/var/spool/mail/username: Each user has a mailbox service

650) this.width=650; "title=" clip_image002 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image002 "src=" http://s3.51cto.com/wyfs02/M01/72/BE/wKioL1Xsbb2T4a9_ Aabadwmvweq723.jpg "width=" 382 "height="/>

Pop3:post Office Protocol Mail receive

IMAP4: Receive mail Internet Mail Access Prococol

Mail command using: Control+d commit

Command format

NAME

Mailx-send and receive Internet mail

Synopsis

MAILX [-bddefintv~] [-s subject] [-a attachment] [-C CC-ADDR] [-B bcc-addr] [-R From-addr] [-H hops] [-a account] [-s Var Iable[=value]] to-addr ...

MAILX [-bddeehiinnrv~] [-t name] [-A account] [-s variable[=value]]-f [name]

MAILX [-bddeeinnrv~] [-A account] [-S variable[=value]] [-u user]

Direct Mail: Enter the interactive mail transceiver interface

Mail-s "Subject" [email protected] email content to be provided interactively

Input redirect Mail-s "subject" [Email protected]</path/from/somefile

command| Mail-s "Subject" [email protected]

Example

Mail-s "HI" [email protected]-S for title

650) this.width=650; "title=" clip_image003 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image003 "src=" http://s3.51cto.com/wyfs02/M02/72/BE/ Wkiol1xsbb6zvxnqaabfgmweklw241.jpg "width=" 312 "height="/>

    • AT command

A job that hosts a future run that supports the use of job queues

The default queue identifier A can be followed by a relative time or an absolute time

At Now+3minute after three minutes (refers to submit task)

Control+d Submitting a task

650) this.width=650; "title=" clip_image006 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image006 "src=" http://s3.51cto.com/wyfs02/M00/72/BE/ Wkiol1xsbb6cr1xxaaaqqhljowo355.jpg "width=" 177 "height="/>

Command format:

At [-v] [-Q queue] [-f file] [-MMLV] timespec ...

At [-v] [-Q queue] [-f file] [-mmkv] [-t time]

At-c job [Job ...]

ATQ [-v] [-Q queue]

At [-rd] job [job ...]

ATRM [-v] job [job ...]

-Q queue at job queues

-f/path/from/somefile: Reads the job to run from the specified location file

-L View Job Queue medium Run job list, equivalent to ATQ

-C At_job_num: Look at the contents of the Run job

Mail recommends using absolute paths

-D Delete at-d 3 to delete the third queue equivalent to ATRM

    • The time representation of at

(1) Absolute time: hh:mm

Mmdd[cc]yy,mm/dd[cc]yy,dd. Mm[cc]yy or [Cc]yy-mm-dd

Tomorrow tomorrow

(2) Relative time Now+=unit Minute,hour,day,week

(3) Blur time Midnight Lunch Moon teatime 4 o'clock in the afternoon

After 15:35 for interactive

650) this.width=650; "title=" image "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/72/BE/ Wkiol1xsbb6zaykcaaafsh8cvbi790.jpg "width=" "height="/>

AT-L Displays the current queue a queue,

650) this.width=650; "title=" image "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/72/BE/wKioL1Xsbb_ Qbuf6aaaksdr6gpu003.jpg "width=" 244 "height="/>

    • Batch:

The system chooses to run the specified task when the resource is more space, similar to at basic

    • Crontab

Recurring Task Scheduler, at which only one time can run at a certain point

Crontab need to be crond by using daemon (check if schedule should run once)

Crond Run as Administrator

There are two types of recurring plans:

(1) System cron task, no default running user identity, need additional runner/etc/crontab directly

Vim command, not recommended

[Email protected] mail]# Cat/etc/crontab

Shell=/bin/bash

Path=/sbin:/bin:/usr/sbin:/usr/bin

Mailto=root

# for details see Mans 4 Crontabs

# Example of Job definition:

#.----------------Minute (0-59)

# |.-------------Hour (0-23)

# | |.----------DAY of Month (1-31)

# | | |.-------month (1-12) OR jan,feb,mar,apr ...

# | | | |.----DAY of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat

# | | | | |

# * * * * * * user-name command to be executed

A total of seven fields: first five field points of time

User-name: Run the task as that user

command to being executed to run a task

(2) User cron task, submitted by a user, run by default as submitter, no need to specify additional runner

/var/spool/cron/username synchronization with users, not recommended for use with VIM

crontab command: Suggest, edit your own daemon

Users have only 6 fields, no user compared to the system

[Email protected] mail]# Cat/etc/crontab

Shell=/bin/bash

Path=/sbin:/bin:/usr/sbin:/usr/bin

Mailto=root

# for details see Mans 4 Crontabs

# Example of Job definition:

#.----------------Minute (0-59)

# |.-------------Hour (0-23)

# | |.----------DAY of Month (1-31)

# | | |.-------month (1-12) OR jan,feb,mar,apr ...

# | | | |.----DAY of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat

# | | | | |

# * * * * * command to be executed

5 minutes: Valid range 0-59

Hours: 0-23

Day (date per month) 1-31

Month 1-12

Weeks (0-7)

Note: The date of the month and the number of weeks, not recommended to use simultaneously

For example, March 6, Week 2, not every March 6 for the Week 2

6 * * * * * Indicates the relationship between each and five, to be satisfied at the same time

Large time asterisk (available values per range)

Point-in-time notation:

*: Each time point within the valid time-point value

6: The number itself is a given time point such as 6 for 6 points (per day).

-: A specific continuous time range of 3-7

,: Represents a discrete time 3,5,7 (such as minutes representing 3,5,7, minutes)

/#: How much time in the effective time range is used to specify the frequency

1-30/4 represents once every 4 minutes in 1-30 */4 every 4 hours

Example

5 */3 * * */bin/ech "howdy" run every three hours after the following command: Note: The 1th bit needs to specify a value, only the meaning of each

5 7 * * 1-5 weeks a Friday, each point 7:5, run the back task

Execution results are sent to customers by mail/bin/usr/bin/sbin/usr/sbin

Controntab only use the above path, it is recommended to use absolute path

650) this.width=650; "title=" image "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/72/BE/wKioL1Xsbb_ Xxk2waabtxlooev0379.jpg "width=" 244 "height="/>

crontab command

crontab [-u user] [-l |-r |-e] [-I.] [-S]

-u User: Not managing your own cron task, but specifying the target user

-L list Tasks

-E default is VIM editor

-R Clears All Tasks

Only the administrator can view all

Example:

1, realize every 8 minutes to run a task? To divide without precise time running, the last time can be different

Here */8 60/8 cannot be divisible, left 4, solve sleep

2. Run a task every 10 seconds? Crontab only supports minutes, not seconds, to use the Sleep command

Subsidy tool: Anacron periodic check of tasks, if the specified time is not executed, whether or not

Point-in-time, to run immediately or specify the time once! , default does not start! Not executed in server

650) this.width=650; "title=" clip_image013 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image013 "src=" http://s3.51cto.com/wyfs02/M02/72/BE/ Wkiol1xsbccalyrnaaa7g4asyak933.jpg "width=" 275 "height="/>

Note: If you do not want to accept notification messages for task execution results

Command>/dev/null success

Command &>/dev/null whether or not it succeeds

(2) for the crontab file has a special function, if the use of%, need to use escape, or use a single

Quote '% ' on it

(3) Crontab's path variable is not exactly the same as the user's variable, so it is recommended that the Cron task use absolute path

Consider using export if you use

Cat/etc/crontab

650) this.width=650; "title=" clip_image014 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image014 "src=" http://s3.51cto.com/wyfs02/M02/72/C2/ Wkiom1xsa5jias9faabct2h3pjo559.jpg "width=" 265 "height="/>

    • Practice:

1, weekly from 1 to Saturday 3:20 A.M., run the tar command to archive the/etc/directory to save

Storage location is/BACKUP/ETC-YYYY-MM-DD.TAR.XZ

Xz/path/to/somefile

-D Decompression Xz–d TEST.TAR.XZ

-#:1-9 Default is 6

-K: Keep files while compressing

Tar Implementation Archive tool, only archive uncompressed CF XF TF

-C Create an archive file

The-F must be followed by a parameter specifying the file name *.tar

-X Expand Archive

--xattrs protects its extended attribute information while archiving

-T does not expand the archive and directly view the files that were archived

Compress the XZ file name after archiving. Tar

-ZCF Direct call is archive re-compression, call gzip

-ZXF call gzip Unzip and archive

-JCF:BZIP2 direct call i.e. archive and re-compress

-JXF:

-JCF:XZ direct call i.e. archive and re-compress

-JXF: Direct call is archive and re-compression

tar-jcvf/tmp/51ctobak/etc-' Date +%y-%m-%d '. tar.xz/etc

where "+%y-%m-%d" can be used%f
Crontab time Format: 20 3 * 1-6

2, every Sunday 2:30 A.M., run the CP command to/etc/fstab file backup, storage location for

/backup/fstab-yyyy-mm--dd-hh--mm-ss

Cp-a/etc/fstab/tmp/51cto/fstab-' Date +%y-%m-%d-%h-%m-%s '

Crontab Time Format 30 2 * 7

3, every night 12 o'clock, get all the lines in the/proc/meminfo file starting with S or M, append to

/statistics/meminfo.txt file and the daily message before, to add a similar =============== separator line;

Grep-o ' ^[s,m].* '/proc/meminfo line with S or M switch

Sed-i "1i ===============" meminfo.txt |grep-o ' ^[s,m].* '/proc/meminfo>/statistics/meminfo.txt

Output:

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/72/BE/ Wkiol1xsbcgqnzzqaabqha3uovw191.jpg "442" height= "/>"

Edit crontab Time Format 0 0 * * *

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/72/BE/ Wkiol1xsbcktbud7aacbk7gbxs0661.jpg "" 648 "height="/>

Run a day to see the results

20150905 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.