Linux Learning-Scheduling tasks

Source: Internet
Author: User

1,at One-time scheduled tasks

Description: Executes a specific command at the time of development

Usage: at time

Option:-M sends a message to the user after the scheduled task execution finishes

-L View User protection tasks

-D Delete User scheduled task

-C View specific content of at scheduled tasks

For example:

[email protected] ~]$ at 2:35 #指定时间是当天的2:35 start to perform scheduled tasks

At>tar CVF Test.tar/study/test.txt

At> cp/study/test.txt/study/test.txt.bak<eot> #回车键后可以输入多条命令, Ctrl+d end input

Job 2 at 2016-08-15 02:35


At-l #查看计划任务

At-c 1 #查看编号为1的计划任务的具体内容

At-d 1 #删除编号为1的计划任务

The time format after the AT command has many, at hours: minutes (the default represents the time of day), at 4pm+3days (representing 3 days after 4 o'clock in the afternoon), at 12:00 2016-08-08 designated month day. Concrete at


2,cron Recurring Scheduled Tasks

First determine if the Crond service is turned on before use, otherwise the scheduled task will not be executed

[[Email protected] study]# service Crond status

Crond (PID 1730) is running ...

[Email protected] study]# chkconfig--list Crond

Crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off

The crontab command uses the following:

Description: Maintain periodic scheduled task files for each user

Usage: crontab [-u Specify user][-l|-r|-e]

Option:-u Specifies the user for the scheduled task, which defaults to the current user

-L View Scheduled Tasks

-R Delete Scheduled Tasks

-E Editing Scheduled Tasks

-I requires the user to confirm the deletion when you delete a scheduled task using the-R

2.1 System customized a lot of scheduled task scripts, placed in the/etc/under the cron.hourly,cron.daily, cron.weekly, etc., if a script needs to be executed every day, you can put the script in the Cron.daily directory, the system will automatically execute daily

[Email protected] study]# ls-d/etc/cron*

/etc/cron.d/etc/cron.deny/etc/cron.monthly/etc/cron.weekly

/etc/cron.daily/etc/cron.hourly/etc/crontab

The time definition file is Anacrontab

[email protected] etc]# cat Anacrontab

#/etc/anacrontab:configuration file for Anacron


# See Anacron (8) and Anacrontab (5) for details.


Shell=/bin/sh

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

Mailto=root

# The maximal random delay added to the base delay of the jobs

Random_delay=45

# The jobs would be started during the following hours only

Start_hours_range=3-22


#period in days delay in minutes job-identifier command

1 5 cron.daily Nice run-parts/etc/cron.daily

7 cron.weekly Nice run-parts/etc/cron.weekly

@monthly cron.monthly Nice run-parts/etc/cron.monthly

The first line means: 65 minutes a day after the boot to check whether the cron.daily file is executed, if not executed today to execute his

The second line means: Every 7 days after the boot 70 minutes to check whether the cron.weekly file is executed, if not executed within a week to execute his

If you want to define this specific time, you can add the following definitions in the Contab file, as follows

  1. # Run-parts

  2. * * * * * Root run-parts/etc/cron.hourly

  3. 4 * * * Root run-parts/etc/cron.daily

  4. 4 * * 0 root run-parts/etc/cron.weekly

  5. 4 1 * * Root run-parts/etc/cron.monthly

[email protected] etc]# cat 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

The time of day and moon is the command


2.2 [[email protected] etc]# crontab-e # Edit Scheduled task, will pop up similar to the VI editing interface

No crontab for root-using an empty one

* * 5 TAR-CZF Log.tar.bz2/var/log #每周五晚23点30分执行日志备份

*/3 * * * * who # every 3 hours to check user login status

* * 3,5 free |mail-s "Memory" [email protected] #每周三, five of 10 points to the system's memory information sent to the mailbox


Safety control of 2.3 crontab:

/etc/cron.allow:
will be able to use Crontab's account to write to it, if not in this file users can not use crontab;

/etc/cron.deny:
You will not be able to use Crontab's account to write to it, if the user is not recorded in this file, you can use crontab.

is a line of an account,/etc/cron.allow than/etc/cron.deny priority, and judge above, these two files only choose one to limit it, therefore, suggest you just keep one, lest affect oneself in set above judgment! In general, the system presets are reserved for/etc/cron.deny, and you can write/etc/cron.deny to the user who does not want him to perform crontab.

When the user uses the crontab command to set up a work schedule, the work is recorded in the/var/spool/cron/, and the account is used as a discriminant. Do not use VI to edit the file directly, because you may not be able to perform cron due to input syntax errors

2.4 Log View:/var/log/cron, there are multiple backups, one week, the current is cron

2.5 anacron--immediately after the Anacron action, he will go to detect the outage period should be carried out but did not carry out the crontab task, and the task is executed once, Anacron will automatically stop, this is because Anacron will be a day, seven days, One months to detect the CRONTAB mission not performed by the system. The general default setting is available.

To determine if the Anacron is active when booting, you can release the following commands: [[email protected] ~]# chkconfig--list Anacron

2.6 Note Service restart: After modifying/etc/crontab, may not be executed immediately, this time please restart Crond this service '/etc/init.d/crond restart '

The week and the sun and the moon cannot coexist simultaneously, cannot use "several months and weeks" the mode work

Linux Learning-Scheduling tasks

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.