Linux system delay tasks and scheduled tasks

Source: Internet
Author: User

I. Delay task

In Linux, the delay task is temporary, you can specify a task to run at a specific time in the future

1. At command

Basic Operation format:

[[email protected] ~]# at now+1minat> date<eot> #EOT代表Ctrl +d to save this delay action Job 2 at 2017-07-29 12:12
At-l|atq Both commands are used to view the current delay task
ATRM | at-d + task number This command is used to cancel a scheduled task.
At-c + task number Viewing the contents of a deferred task
At-f file The action in the deferred task execution file. Note that the file is not a script
At Now+1min 1 minutes delay
At-m The delay command has no output and sends an e-mail to the performer, and no output is sent by default.
At-m Delay command Even if there is output, do not send mail to the performer

2. At execution command right setting

/etc/at.deny # User blacklist, users in this list cannot execute the at command

/etc/at.allow # User Whitelist, This file does not exist by default , after the establishment of all users do not have at command execution permission, this list of users have at command execution permissions.

Second, Scheduled Tasks

Scheduled task is permanent, in the system every minute do task scan, his task program is Crond

[[Email protected] ~]# ll /etc/|grep cron-rw-r--r--.   1 root root    541 Jul 19  2011 anacrontab   drwxr-xr-x.   2 root root   4096 May  1 20:43 cron.d    drwxr-xr-x.  2 root root   4096 apr  5 21:54  cron.daily     #每天都要执行一次的定时任务-rw-r--r--.   1 root root    0 Jul 19  2011 cron.denydrwxr-xr-x.  2 root root    4096 Apr  5 21:51 cron.hourly    #每小时都要执行一次的定时任务drwxr-xr-x.   2 root root   4096 apr  5 21:53 cron.monthly    #每月都要执行一次的定时任务drwxr-xr-x.  2 root root   4096 sep 27   2011 cron.weekly    #每周都要执行一次的定时任务-rw-r--r--.   1 root root   457 sep  27  2011 crontab[[email protected] cron.d]# cat /etc/crontab  shell=/bin/bash        #执行定时任务的shellPATH =/sbin:/bin:/usr/sbin:/usr/bin    #全局路径MAILTO =root            #邮件的接收者  home=/# The following is the meaning of the first five   "*" of a scheduled task # for details see man 4 crontabs# example of  job definition:# .---------------- minute  (0 - 59) # |  .--- ---------- hour  (0 - 23) # |  |  .---------- day of  month  (1 - 31) # |  |  |  .------- month  (1 &NBSP;-&NBSP;12)  OR jan,feb,mar,apr ...# |  |  |  |  &nbsp.----&NBSP;DAY&NBSP;OF&NBSP;week  (0 - 6)   (sunday=0 or 7)  or sun,mon,tue,wed,thu,fri,sat# |   |  |  |  |# *  *  *  *   * user-name command to be executed

1. Initiating mode one: using the crontab command to initiate

The principle is to add your scheduled tasks in the/var/spool/cron/file that corresponds to the user's name.

[[email protected] ~]# ll/var/spool/cron/total 16-rw-r--r--1 root root 285 May 3 20:13-rw-------1 root root 2 9 13:06 feitian-rw-------1 root root Jul 13:08 loveyu-rw-------1 root root 476 Jul 13:04 root
Crontab-u Specify which user this timer task belongs to
Crontab-l List the current user's scheduled tasks
Crontab-e Edit the current user's scheduled tasks

1 " General crontab timed task syntax

* * Number, indicating any time, the actual meaning of "every" time, such as * * * cmd represents the daily 23:00 per month of the execution of the CMD task. Note that each time is on the * for each, if the bit is * is the value range of the time on the bit, the hour * is equivalent to 00-23-minus, representing the delimiter, representing a range, interval segment, such as 17-19 points per day of the 17,18,19 00 points to the task, comma, Indicates the meaning of the separated time period; 17,18,19 * * */bin/sh/scripts/feitian.sh, representing 17, 18/19 points per day to execute/scripts/feitian.sh script, can and-in conjunction with the use of/MN representative debriefing, That is, every n time unit, for example, every 10 minutes to perform a task can be written as */10 * * * * cmd, where */10*,* range is 0-59 can also be written as 0-59/10;
05 * * * * 5 minutes per hour on the punctuality.
05 02 8 * * * 2.05am per day
30 08 1 * * First day of the month 8:30pm
00 07 25 12 * December 25 7:00am
30 16 * 5 Every Friday 4:30pm
*/5 * * * * Executes every 5 minutes
*/10 9-17 1,15 * Every 10 minutes between the first day of the month and the 15th day 9:00am to 5:00pm
0 0 0 0 Jan 0 January 1 midnight and every Sunday of January
[Email protected] ~]# crontab-u loveyu-ecrontab:installing new crontab[[email protected] ~]# crontab-u loveyu-l* /1 * * * * echo "Feitian" >>/mnt/fenghui# every minute to add Feitian this string to Fenghui this file

2, Initiation mode two: Use Vim/etc/cron.d/filename

This way is similar to the above crontab, but completely and crontab no relationship, that is, in the back of time more than a user, that is, the owner of the scheduled task.       

* * * * * * Root Touch/mnt/file # #表示每分钟在 Create a file in the/mnt directory

3, the implementation of the crontab command of the right to set

/etc/cron.deny # # User blacklist, users in this list cannot execute crontab command ( write user name directly in file )

/etc/cron.allow # # user Whitelist, this list default does not exist , after the establishment of all users do not have at command execution permission, this list of users have crontab command execution permissions.

Third, temporary files in the system

The system in the normal operation of the service will produce temporary files, he will be in the system /usr/lib/tmpfiles.d/ directory, the system's temporary file configuration configuration is /usr/ lib/tmpfiles.d/*.conf, the temporary file profile that you create must end in . conf .

temporary file configurations are written in the following ways:

File type filename File permissions file owner file All group files exist at least D/mnt/westos 777 root root 10s # #表示在/mnt directory to create a temp directory Westos,    and cannot be deleted within 10 seconds systemd-tmpfiles--create/usr/lib/tmpfiles.d/* # #执行临时文件配置 Systemd-tmpfiles--clean/usr/lib/tmpfiles.d/* # #清理临时文件



This article is from the "13122323" blog, please be sure to keep this source http://13132323.blog.51cto.com/13122323/1952782

Linux system delay tasks and scheduled 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.