#22 system process scheduling, at, batch, mail, crontab

Source: Internet
Author: User

Process scheduling for Linux systems (Task Scheduler)

Schedule: At some point in the future, let the system automatically execute a list of the commands or scripts we have written beforehand, so that the task can be completed on time even if the user is not near the computer;


In order to be able to process scheduling, it is necessary to have a mechanism to identify the time of occurrence of the event and to run the user's expected command, which is implemented in Linux through a specific daemon process;

This type of daemon includes:

Atd

The pre-written commands are executed at some point in the future;

Crond

The pre-written commands are repeated at the next qualifying point in time;


To see if such daemons are working correctly:

CENTOS6:

Service {Atd|crond} status


The result is Runnig or "running", which indicates that it is working correctly


CENTOS7:

Systemctl Status {Atd.service|crond.service}


The result is active (Runnig), which indicates that it is working properly


All the results of the process scheduling will be sent to the user's mailbox by e-mail;

Local Email service:

Smtp:simple Mail Transfer Protocol, Simple Mail Transfer Protocol, TCP/25;

Pop3:post-office Protocol version 3, Post Office Protocol, third edition, tcp/110;

Imap4:internet Mail Access Protocol version 4, fourth edition of the Internet Mail Protocol, tcp/143;


The entire e-mail system is divided into four parts:

Mua:mail user agent, mail user agent, to help users send e-mail to the server or to help users receive e-mail from the server application;

Mta,mda,mra


Common MUA:

Browser, OUTLOOK,FOXMAIL,MAIL|MAILX


Mail [-S SUBJECT] username[@HOSTNAME]


/var/spool/mail/username is the mail for each user;


In order to be able to send messages non-interactively, you can use input redirection or pipelines;


The ATD daemon can identify and complete a task plan made by the AT command and Batch command;


Recurring Task Scheduler: Cron

Cronie software package, provide cron daemon and other management tools of cron;


Cron tasks typically fall into two categories:

System Cron Task:/etc/crontab


Shell=/bin/bash

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

Mailto=root

home=/


# 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


Attention:

1.

* * * *: Defines the time of day to perform tasks

User-name: User account identity for running this task;

command to be executed: The task command and command line parameters that should be executed;

Note: In order to ensure that the task can be executed accurately, the command is usually filled with absolute path;


2. Separate each field with one or more whitespace characters;


3. The results of the task run are sent directly to the root user by mail;


User Cron Task:/var/spool/cron/username


Shell=/bin/bash

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

Mailto=root

home=/


# 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


Attention:

1.

* * * *: Defines the time of day to perform tasks

command to be executed: The task command and command line parameters that should be executed;

Note: In order to ensure that the task can be executed accurately, the command is usually filled with absolute path;


2. Separate each field with one or more whitespace characters;


3. The results of the task run are sent directly to the user by mail;


Time notation:

1. Specific time: All valid values in the range of valid values for a given point in time;

0 5 3 9 *

0: Minutes

5: Hours

3: Date

9: Month

*: Week

2. Wildcard Time: *, meaning "every ..." means, all valid values for a given time;

*  *  *  *  *

3. Discrete time: At a given point in time, use commas to separate;

0 8,20 * * 1,3,5

Weekly 1,3,5 8 o'clock to 8 o'clock in the evening

4. Continuous time: At a given point in time, use a minus sign to separate;

0 8 * 1-5

5. Step time: E-commerce at a given time, using division sign separation;

*/2 * * * *

*/7 * * * * This method does not implement scheduled tasks every 7 minutes (units must be divisible);


Attention:

1. The specified step length must be divisible by the value of the time point, otherwise, meaningless;

2. The minimum time unit is the minute, and if the plan takes seconds as the unit of time to execute the scheduled task, other mechanisms must be used;


At: Executes the command at the specified time.

Options:

-Q QUEUE;

-F FILE;

-L: View queue, equivalent to ATQ;

-D job_id: Clears the specified scheduled job, equivalent to ATRM;

C: Want to see the top of the job content;

At [option] Time

Time

1.hh:mm [YYYY-MM-DD]

2.noon,midnight,teatime

3.tomorrow

4.now+ #UNIT Unit:min,hours,days,weeks,months,years, ...


At-defined jobs have the concept of a queue, usually the queue is represented by a single letter, the default is A;

At-q queue_name Time

Example:

At 5pm+3 Day (three days after the 5 o'clock in the afternoon Chung execution/bin/ls)

At>/bin/ls

At> Job 7 at 2013-01-08 17:00


Batch command: The batch command does not need to specify the time when the task is defined, it is the system's choice when the system compares space to complete the task, the other configuration is identical to the AT command;

Options:

-F: Specifies the task file containing the specific instructions;

-Q: Specifies the queue name for the new task;

-M: Sends an e-mail message to the user after the task is executed.

Example:

Batch

at> Echo 1234

At> <EOT>

Job 5 at Sun APR 28 08:49:00 2013


Mail: The email send and receive tool for the command line.

Options:

-b< Address: Specify the addressee address of the blind copy;

-c< Address: Designated copy of the recipient's address;

-f< mail file;: Reads messages from the specified message file;

-I: Do not display the information sent by the terminal;

-I: Use interactive mode;

-N: When the program is used, the settings in the Mail.rc file are not used;

-N: When reading a message, the title of the message is not displayed;

-s< mail subject;: Specify the subject of the message;

-u< user account;: Read the message of the specified user;

-V: Displays detailed information when executed.

Example:

Mail-s "Hello from Linuxde.net by Shell" [email protected]

Hello,this is the content of mail.

Welcome to Www.linuxde.net

Attention:

The first line is the input command,-s for the subject of the message, the following [email protected] is the recipient of the message, after entering this line of command, enter the message body will be written, we can enter any text, such as the above two lines. When the message body input is completed, you need to press Ctrl+d to end the input, you will be prompted to enter the CC address, that is, the mail cc address, no direct return to complete the message sent.


Crontab: A recurring task for submitting and managing users, similar to a scheduled task under Windows, when the operating system is installed, the Service tool is installed by default, and the Crond process is automatically started, and the Crond process periodically checks for the tasks to be performed every minute. If there is a task to perform, the task is automatically performed.

Options:

-u username: used by Superuser to set or edit user cron tasks for other users;

-L: View all the scheduled tasks that have been defined;

-e: Edit the crontab file using the VI editor;

-R: Removal of all scheduled tasks, not recommended;

-I: Interaction when using the-r option;

Example:

Crontab-e

*/6 * * * * * sleep '; ' ls >/dev/null


#22 system process scheduling, at, batch, mail, crontab

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.