Linux commands: Task Scheduler crontab Anacrontab at cron

Source: Internet
Author: User


Task Schedule:

1. Perform one task at a time in the future: at Batch

Format: At time at-l View Schedule list

At> COMMAND

At> Ctrl+d

Specify time:

Absolute time: hh:mm DD. Mm. YY Mm/dd/yy

Relative Time: now+#

Unit: Minutes,hours,days,weeks

Blur Time: Noon,midnight,teatime

The execution result of the command is sent to the user who scheduled the task as a message

At-l View non-executed scheduled Tasks at-l=atq

At-d job_id Canceling an unscheduled scheduled task at-d scheduled task ID number

At blacklist and whitelist files/etc/at.deny/etc/at.allow

[Email protected] ~]# at-l

[Email protected] ~]# at-l

32016-12-17 08:36 a root

22016-12-17 08:28 a root

[Email protected] ~]# at-d 2

[Email protected] ~]# at-l

32016-12-17 08:36 a root number 2 task schedule canceled

Usage:

[[email protected] ~]# at now+3minutes 3 minutes after execution

At> Ls/var need to execute Ls/var command

At> Cat/etc/fstab need to execute Cat/etc/fstab command

at> <EOT> Complete Task plan by ctrl+d

Job 1 at 2016-12-17 08:16

[Email protected] ~]#

2. Perform a task periodically: the results of the execution will be sent to the administrator in the form of mail

Cron: Self is a service that runs uninterrupted

Anacron:cron, can be implemented to enable cron for various reasons in the past time the execution of the task did not perform the normal execution once;


cron configuration file:/etc/crontab

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

Shell=/bin/bash #定义执行脚本的shell为/bin/bash

Path=/sbin:/bin:/usr/sbin:/usr/bin #定义脚本执行的环境变量位置

Mailto=root #执行结果发送给root用户

home=/ #家目录


# Run-parts: indicates that all command scripts are executed in the order of the directory or document

* * * * * Root run-parts/etc/cron.hourly the first minute of every hour

4 * * * Root run-parts/etc/cron.daily daily 4:02

4 * * 0 root run-parts/etc/cron.weekly every Sunday 4:22

4 1 * * Root run-parts/etc/cron.monthly monthly 1st 4:42

Cron:

System Cron Task:

Configuration file/etc/crontab

Format: minutes, hours, days, months, weeks, user tasks

User Cron Task:

Configuration file/var/spool/cron/username

Format: Minutes Hours day Month Week task

Valid values for TIME:

Minutes: 0-59 Hours: 0-23 days: January-3 January: 1-12 weeks: 0-7,0 and 7 denote Sunday

Time-Pass representation:

*: All valid values corresponding to

3 * * *: 3rd minutes per hour

3 * * 7: Every Sunday hour of the 3rd minute

13 12 * *: 12 points per day, 13 minutes

,: Discrete point in time:

10,40 02 * * 2,5: Every Tuesday, Friday 2:10 and 2:40

-: Continuous point in time:

10 02 * 1-5: Every Monday to Friday 2:10

/#: Each time within the corresponding range of values must be fixed at a point in time that is smaller than each unit

*/3 * * * *: every 3 minutes

10 */2 * *: executed every 2 hours

10 06 */2 * *: Executed every 2 days

CRON environment variable: Cron executes all commands to go down the path specified by the PATH environment variable


3, the user task management:

Crontab to crontab execution, the Crond service must be running,

View the running Status service Cront status


[[Email protected] ~]# service Crond status

Crond (PID 3733) is running ...


-L: Lists all cron tasks for the current user

-e: Edit the cron task, press A to enter, press ESC and enter: Wq Save to exit.

[[email protected] ~]# crontab-e First enter crontab-e and press A to edit,

After editing, press ESC and enter: Wq Save to exit.

*/3 * * * */bin/echo "How is it?"

-r: Delete all cron tasks and remove only one of the scheduled tasks, just crontab-e edit to delete the tasks

-u:username managing Cront tasks for their users

Anacrontab:/etc/anacrontab


This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1883578

Linux commands: Task Scheduler crontab Anacrontab at 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.