Linux Mission plan

Source: Internet
Author: User
Tags egrep

Linux Mission plan


Before you know the Linux task plan, learn about the mail service for Linux, because the Task Scheduler calls the Mail mail service to send messages by default. The following is a preliminary understanding of mail messaging services. The main way to send mail, view mail and so on.

Common Mail Application Protocol:

SMTP: (easy Mail transmission Protocol) Simple Mail Transfer Protocol, TCP 25 port, Smtps (Linux OS enabled by default SMTP service)

POP3: (Post Office Protocol) 3rd edition Post Office Protocol, TCP 110 port, POPs

IMAP4: (Internet Mail access Protocol) Internet Message Access Protocol, TCP 143 port, Imaps

Mine/mime: (Multipurpose Internet Mail Extensions) multipurpose, multi-function Internet Mail Extensions: Binary data is re-encoded as text, and binary data can be sent as a text protocol. Common coding Method: base64.

Syntax: Mail [-iinnv][-b< address >][-c< address >][-f< mail file >][-s< message subject >][-u< user account >][delivery address]

Common parameter Options

-F: Reads messages from the specified message file

-S: The subject of the message

-u<username>: Read messages for a specified user


Three commonly used formats for sending letters

1, the current shell as an editor to use, finished editing the content Ctrl+d end

Mail-s mytest [email protected]

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/B5/wKiom1XryBmQCXrBAALX9dRpveo440.jpg "title=" 1.jpg " alt= "Wkiom1xrybmqcxrbaalx9drpveo440.jpg"/>

2. Send with pipeline editing content

echo "MyTest mail Mytest2" |mail-s mytest2 [email protected]

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/B1/wKioL1Xryk7Ts8blAAMqWum5p1E610.jpg "title=" 2.jpg " alt= "Wkiol1xryk7ts8blaamqwum5p1e610.jpg"/>

3. Send the contents of the document as the mail content

Mail-s mytest3 [email protected] </tmp/mytest3.txt

Task scheduling can be divided into two types: one-time task job (at command, Batch command), recurring task job (crontab command, Anacron)

One-time task job: At, an interactive command with two execution modes: interactive, which allows the user to enter one or more commands at the At> prompt, batch, write the task's command to the file, and the at call

The difference between batch commands and at is that batch cannot set the execution time, only the system automatically chooses the idle time to execute, here does not do too much introduction, just simply understand

Note: Ctrl+d is the job to submit, and the result of the task execution is sent by default to the submitter by mail

Syntax: at [parameters] point in time

Common parameter Options

-V: Shows when the task will be executed

-C: Display the contents of a task

-q< queue;: Specify queue

-f< file: Reads the job to run from the specified file

-t< Time parameter: Submit the task to run in the form of a time parameter

Time: Format

HH:MM (Hours: minutes)

Midnight (Late night), noon (noon), Teatime (tea time, usually 4 o'clock in the afternoon)

Now+time-units, now is the current time, Time-units is the time unit, can be minutes (minutes), hours (hours), Days (day), Weeks (week) 22

The following interactive mode, example: Perform view/tmp directory information at 22:01, display/etc/fstab automatic mount information two tasks

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/B5/wKiom1XryDjBlgUNAAFJWu8Vfrg022.jpg "title=" 3.jpg " alt= "Wkiom1xrydjblgunaafjwu8vfrg022.jpg"/>650) this.width=650; src= http://s3.51cto.com/wyfs02/M02/72/B1/ Wkiol1xrymqwkpnsaaeq7kxmstg572.jpg "title=" 4.jpg "alt=" wkiol1xrymqwkpnsaaeq7kxmstg572.jpg "/>650) this.width= 650; "Src=" http://s3.51cto.com/wyfs02/M02/72/B5/wKiom1XryEyQx709AAQOBn090l0963.jpg "title=" 5.jpg "alt=" Wkiom1xryeyqx709aaqobn090l0963.jpg "/>

Note: The job has a queue concept, by default, all jobs are under one team, the job list is [A-z], using the command AT–Q [a-z]

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/B1/wKioL1Xryn_haIhXAAHqjaJhaeE549.jpg "title=" 6.jpg " alt= "Wkiol1xryn_haihxaahqjajhaee549.jpg"/>

The following file modes, example: Executing a file at 23:00 fileat,fileat viewing/tmp directory information and displaying/etc/fstab automatic mount information

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/B5/wKiom1XryGPDBdC-AAHL4tLQ7os240.jpg "title=" 7.jpg " alt= "Wkiom1xrygpdbdc-aahl4tlq7os240.jpg"/>


Recurring Task Jobs

Crond is the daemon: a process that runs in the background and listens to a user's requests at any time.

Cron sub-system level and user level, system level: The system is executed automatically, with the system environment variable (non-login shell) to run the process, so the script is called when the command is recommended to write the full path, otherwise the execution script will appear


When the path is not found. Execution results are sent by default to the root user, and if you do not want to send mail, the task job is redirected to/dev/null (also known as a black hole)

System cron file is saved in/etc/crontab, user crontab in/var/spool/cron/username

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/B1/wKioL1XrypXD6zeIAALbLfPgg6E078.jpg "title=" 8.jpg " alt= "Wkiol1xrypxd6zeiaalblfpgg6e078.jpg"/>

Syntax: crontab–l|-r|-e|-i [username]

Common parameter Options

-L: Displays the contents of the job file

I give hints before I work, often with R

-R Delete Job task

-e Edit Job task

Administrator Plus-u can assign tasks to ordinary users: crontab–l–u [normal user]


The following highlights the considerations described above:

(1) If you do not want to receive notification messages for task execution results: command >/dev/null or command &>/dev/null

(2) for crontab file,% has a special function; If a% is present in the command, remember to escape, or use single quotation marks to refer to it

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

The following is a brief analysis of the time format in crontab

# 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


First paragraph: minutes 0-59

Second paragraph: Hours 0-23

Third paragraph: Date 1-31

Fourth paragraph: Month 1-12

Fifth: Days of the week, 0 for Sunday 0-6


Give some small examples to illustrate the time notation:

1) Each time should use the value within its available valid range of values;

2 3 4 * *//4th, 3:2

2) A time position * indicates that each

* 3 4 * *//4th No. 3 every minute is executed

3)-: consecutive time adjacent to the value

15-18 3 4 * *//4th # 3 points 15 to 18 minutes per minute execution

4),: Discrete time value

10,15,20 3 4 * *//4th 3 points 10 points 15 points 20 minutes each execution

5)/#, indicating every # once in a specified time range

*/15 3 4 * *//4th 3 points every 15 minutes

6) If we don't ... To see the results of the execution, you can redirect the output, such as:

0 */2 * * */bin/echo "mytest1" &>/dev/null

Example: Number 4th 3:2 View/etc/fstab file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/B5/wKiom1XryHyRu4meAAFzwm6yIHk687.jpg "title=" 9.jpg " alt= "Wkiom1xryhyru4meaafzwm6yihk687.jpg"/>

Note: Anacron and Cron are similar to the Task Scheduler, except that it does not require the system to run continuously, it can be used to run daily, weekly, and monthly jobs normally run by Cron, and the tasks are listed in the configuration file/etc/anacrontab. For each task, Anacron first determines whether the task has been executed within the period specified in the Period field of the configuration file. If it has not been executed within a given period, Anacron waits for the number of minutes specified in the Delay field and executes the command specified in the command field;


Practice:

1, every Monday to Saturday 3:20 A.M., run the CP command to archive the/etc/directory, storage location is/BACKUPS/ETC-YYYY-MM-DD;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/B1/wKioL1XryqzhmIxCAACvAVXnDC8992.jpg "title=" 10.jpg "alt=" Wkiol1xryqzhmixcaacvavxndc8992.jpg "/>

2, every Sunday 2:30 A.M., run the CP command to backup the/etc/fstab file, the storage location is/BACKUP/FSTAB-YYYY-MM-DD-HH-MM-SS

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/B5/wKiom1XryI7BLnKwAAGhPolky2E966.jpg "title=" 11.jpg "alt=" Wkiom1xryi7blnkwaaghpolky2e966.jpg "/>

3, every night 12 o'clock, get all the lines in the/proc/meminfo file starting with S or M, append to the/statistics/meminfo.txt file, and before the daily message, add a similar =============== separator line

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/B1/wKioL1XrysWD4CQiAAGcfTnGarE629.jpg "title=" 12-1. JPG "alt=" wkiol1xryswd4cqiaagcftngare629.jpg "/>

or use

0 0 * * */usr/bin/egrep (egrep ' ^ (s| M) '/proc/meminfo;echo "====================") >> Statistics/meminfo.txt


This article is from the "10,000-hour Law" blog, be sure to keep this source http://daisywei.blog.51cto.com/7837970/1691864

Linux Mission plan

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.