A brief summary of Linux recurring Task Scheduler at and Cron

Source: Internet
Author: User
Tags egrep

One-time mission plan: At,batch

Recurring Task Scheduler: Cron

At: Simple usage

At time


Submit Task: ^c+d

Job Result: Send the current user on the system as a message

Send and receive mail:

Service start or Not Status View command:

NETSTAT-TNL |grep ": 25"

The default send and receive messages are only made between users on this computer and only through addresses on the loopback interface.

# Mail

Q: Exit

N: View Nth message

Send an email to the specified user (within the system):

# Mail username[@HOSTNAME]

-S "SUBJECT" theme

echo | Mail can also use pipelines

Format of Time

Exact time:


Blur Time:

now+ #UNIT

Noon, Midnight,teatime, tomorrow

Job Queue view:

At-l, ATQ

To delete a job that has not been run:

at-d [Job_num], at RM

You can also put all the tasks at the at to be executed in the file so that at reads this file as the task to be run (for a large amount of jobs)

At-f/path/to/somefile Time

Batch: No time is required and will automatically run at a later point in time for a system resource that is idle

Recurring Task Scheduler: Cron

Rely on background services to view the running status

Service Crond status CentOS {5,6} version view command, you can use cron if you have the following output

Crond (PID 1680) is running

There are two types of cron tasks:

System cron:/etc/crontab

User cron: Defined in a file with the same name as the user name in the/var/spool/cron/directory

Each row defines a separate task:

The following information is available after viewing/etc/crontab

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




# 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

Consists of the following 3 parts:

Point in time (recurring task)

User-name: User Identity

Command: The task to run

Note: It is recommended that when you define a cron task, the command you use uses an absolute path, or a custom environment variable that has a full path.

Time notation:

1. Each time is a value in the range of valid values that should be used for the period, * to represent all valid values for the period of use,

2. */#: At the corresponding time bit valid value on every # time unit once

Note: The range of values defined for a minute should be divisible by 60

3. Continuous point of time:-

4. Discrete point-in-time:,

Results after the task is run: The message is sent to the task-related user:

Drop message notification: output redirection

COMMAND >/dev/null

COMMAND &>/dev/null

COMMAND >/dev/null 2>&1

/dev/null: Software-simulated device, bit bucket, data black hole

Definition of User cron task:

crontab command:

-L: Lists all tasks that have been defined

-E: Open editor

-r:remove, remove All Tasks

-u User: Not managing your own cron task, but specifying the target user's cron task; root only has permissions to manage other users ' cron tasks; By default, manage your own

Note: The% in the crontab file must be escaped or referenced in single quotation marks.


Every Monday to Saturday 3:20 A.M., run the CP command to save the/etc/directory for archiving, the storage location is/BACKUPS/ETC-YYYY-MM-DD

3 * * 1-6/bin/cp/etc/backups/etc-$ (date+ '%y-%m-%d ')

[[email protected] ~]# mkdir-p/backups/etc[[email protected] ~]# crontab e[[email protected] etc]# CRONTAB-L20 3 * * 1- 6/bin/cp/etc/backups/etc-$ (date + '%y-%m-%d ')

Every Sunday 2:30 A.M., run the CP command to back up the/etc/fstab file with a storage location of/BACKUP/FSTAB-YYYY-MM-DD-HH-MM-SS

2 * * 7/bin/cp/etc/fstab/backup/fstab-$ (date + '%y-%m-%d-%h-%m-%s ')

[[email protected] etc]# mkdir-p/backups/fstab[[email protected] etc]# crontab e[[email protected] etc]# crontab L30 2 * * 7/bin/cp/etc/fstab/backup/fstab-$ (date + '%y-%m-%d-%h-%m-%s ')

Every night 12 o'clock, get all lines in the/proc/meminfo file that begin with S or M, append to the/statistics/meminfo.txt file, and precede the daily message with a similar =============== separator line

6 0 * * */bin/egrep/proc/meminfo "^[s,m].*" >>/statistics/meminfo.txt && Echo ========================= = >>/statistics/meminfo.txt

[[email protected] etc]# mkdir-p/backups/fstab[[email protected] statistics]# crontab E[[email protected] statistics]# C RONTAB-L6 0 * * */bin/egrep/proc/meminfo "^[s,m].*" >>/statistics/meminfo.txt && Echo ================ ========== >>/statistics/meminfo.txt

A brief summary of Linux recurring Task Scheduler at and Cron

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.