Marco Linux Learning (Linux Task Scheduler)

Source: Internet
Author: User

There are two points to perform on Linux on a task schedule :

1. The command to execute a task plan at one time in the future has at , batch

2, the periodic implementation of a task plan has crontab

The message body needs to be accepted interactively

below is a description of the commands for the Linux Task Scheduler

At command:

A job that carries a future time

Support for using job queues

default to a queue

For example:at Now+3minute// Specify future time to execute job

Submit Job Usage Ctrl+d

Common options:

-Q at job Queue

-F reads the job to run from the specified file

-L View a list of such running jobs in the job queue; equivalent to using the atq command

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

-D: delete the specified job; equivalent to ATRM

Batch Command:

The Batch command time is the task that the system chooses to run when the resource is idle, and the remaining parameters are basically the same as the AT command.

The Crontab command is used to set the instructions that are executed periodically. The command reads the instruction from the standard input device and stores itin a "crontab" file for later reading and execution. crontab stored instructions are activated by the daemon, Crond often run in the background, checking every minute for scheduled jobs to be executed. This type of work is generally called cron jobs.

Recurring Task Schedule

Daemon:crond

There are two types of recurring plans:

1, system cron task, no default running user identity, all need to specify the additional runner

In the first category, we use vim editing to

# exampleof Job Definition:

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

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

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

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

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

# |  | |  | |

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

system Tasks consist of 7 fields, the first 5 of which are point -in- time

User-name: Run the task as a user

command to being executed: to run a task

2, the user cron task, submitted by a user, by default, as the identity of the submitter run, so no additional specified

Run by

The second class does not recommend the use of the WIM command, and it is recommended that crontab be executed

User Tasks are made up of 6 fields

5 Time points:

minutes: Valid value range 0-59

Hours:0-23

Day:1-31

Month:1-12

weeks:0-7

Note: The number of months of the week, not recommended for colleagues to use

For example:

6 * * * *

Time notation:

*: each time point in the valid value range of the time point;

-: A specific continuous time range , 3-7

,: A discrete point in time , 3,5,7

/#: The amount of time in a valid time frame, for specifying the frequency;

1-30/4, */4

5 */3 * * */bin/echo "howdy"

5 7 * * 1-5/bin/echo "Howdy"

Crontab Command:

crontab [-u user] [-l |-r |-e]

-u User: not to manage your own cron task, but to specify the target user's cron task; Root has the ability to manage other users ' cron tasks; default management of their own;

-l:list, list the tasks;

-r:remove to remove all tasks;

-e:edit, edit, open a default editor for the current shell session to edit the Cron task table

title: Every Monday to Saturday of the early morning 3 points , run the CP command to Save the/etc/directory archive, storage location is /backups/ Etc-yyyy-mm-dd

[[email protected] ~]# CRONTAB-L20 3 * * 1-6/bin/cp/etc-rpf/backups/etc-' file\%y-\%m-\%d '

title: Every Sunday wee 2 minutes, run the CP command to backup the/etc/fstab file, storage location is /backup/ Fstab-yyyy-mm-dd-hh-mm-ss

[[email protected] ~]# CRONTAB-L30 2 * * 7/bin/cp/etc/fstab/backup/fstab-' file\%y-\%m-\%d-\%h-\%m-\%s '

q : every night , get all lines starting with S or M in the/proc/meminfo file , append to /statistics/ Meminfo.txt file, and the daily message is preceded by a similar =============== separator line

[[email protected]/]# crontab-l00 0 * * * echo "=========================" >>/proc/meminfo | Egrep "^s|^m"/proc/meminfo >>/statistics/meminfo.txt


This article is from the "8430482" blog, please be sure to keep this source http://8440482.blog.51cto.com/8430482/1692514

Marco Linux Learning (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.