Delay task at, timed task cron, temporary file management

Source: Internet
Author: User
Delay Task at

1.at command
How to use:

At   now+5min| time
> Command
>ctrl + D

Example:

At 14:20
at> date
at> <EOT>
Job 2 at Sun Oct 29 14:20:00 2017

At Now+5min
at> date
at> <EOT>
Job 3 at Sun Oct 29 14:27:00 2017

At-     L     |   ATQ                # #查看未执行的延时任务
atrm   IP     |   At-     D          # #终止延时任务

          at-M # #延时任务有输出不产生邮件, exit message using Q

At-    c    IP     # #查看延迟任务的内容

       at-M # #延时任务无输出产生邮件 Mail          # #查看邮件的内容, mail in/var/spool/mail/kiosk

At-    f   filename    # #将文件内容中的命令作为延时任务的动作


2. Blacklist
/etc/at.deny # #at命令黑名单配置文件

Vim  /etc/at.deny
kiosk

at 18:00      # #kisok被加入黑名单, using the permission of at is prohibited from you doing not have permission to use at
.

3. White List
Touch/etc/at.allow # #建立at命令白名单配置文件, white list appears, blacklist expires. All users cannot use the at

Vim/etc/at.allow # #编辑白名单, add Westos users, only westos users and root users can perform at command timed tasks cron

Cron is provided by Crond.service
The time and event of the write program is persisted

1. Setting the way
(1) Order mode
Crontab-u-E # #参数可不写

Minutes of the       month   Week   Events
* * *   rm-rf/mnt/*     # #每天的06:58 Execute Rm-rf/mnt *   1,15 * *   rm-rf/mnt/*     # #每月1日和15日的06:58 Executive rm-rf/mnt/*    06   1-15      *   *   rm-rf/mnt/*     # #每月1日至15日的06:58 Executive rm-rf/mnt/*   1,15      3   *   rm-rf/mnt/*     # #3月1日, 15th, 06:58 executive rm-rf/mnt/*   1,15      3   3   RM-RF /mnt/*     # #3月1日, 15th 06:58 and March each Wednesday 06:58 executed rm-rf/mnt/*
\*/2 06-17  *   1-5  rm-rf/mnt/*     # #周一到周五的每天早上6点至下午的5点之间每隔2分钟执行rm-fr/mnt/* Events

Note: The execution of multiple events is not performed according to the order of events, and the execution of the event is based on the efficiency of the execution of the order, such as RM-RF precedence over the touch.

(2) file mode definition Crontab
vim/var/spool/cron/Username # #以某用户身份执行cron, file name must be consistent with user name

   daily   Week      action

vim/etc/cron.d/File # #设定多个用户身份执行cron

   time of   Day   month   Week    user   action

Attention:
When user root uses the file method to define crontab, the user executing the action is executed as the root user. Even if the user is blacklisted, the action can still be performed.

2. Edit Events

Crontab          -E
          #编辑事件          -L # #列出事件          -R # #删除事件
          -R-I      # #删除任务时会询问是否删除, enter Y to delete-
          R -  u  student    # #以student用户执行事件


/var/spool/cron/* # #cronrenwu存储位置

Black and white list of 3.cron
By default, the system only has a blacklist, and when the whitelist is established, the blacklist is invalidated

(1) blacklist
/etc/cron.deny

Vim/etc/cron.deny
westos

crontab-e you
(westos) are don't allowed to the use this program (CRONTAB)
Ontab (1) for the more information

(2) White list
Touch/etc/cron.allow # #建立at命令白名单配置文件, white list appears, blacklist expires. Cron is not available to all users.

Vim/etc/cron.allow # #白名单中添加westos用户, only root and Westos users can use cron.
Westos

(3) file mode definition Crontab
vim/var/spool/cron/Username # #以某用户身份执行cron, file name must be consistent with user name

   daily   Week      action

vim/etc/cron.d/File # #设定多个用户身份执行cron

   time of   Day   month   Week    user   action

Temporary file Management

vim/usr/lib/tmpfiles.d/westos.conf # #编写管理临时文件的配置文件, westos.conf custom for user

  D      /mnt/westos     777       root     root    10s      |
 | | | Directory for temporary Files directory directory directory where the user owns the group to clean up the files in the directory time interval


systemd-tmpfiles–create/usr/lib/tmpfiles.d/* # #执行管理临时文件配置文件
systemd-tmpfiles–clean/usr/lib/tmpfiles.d/* # #清理超过配置文件设定时间的文件


Reopen a window for monitoring: Watch-n 1 ls-lr/mnt/
After the original window touch/mnt/file1,10s execution systemd-tmpfiles–clean/usr/lib/tmpfiles.d/*, will find/mnt/file1 disappeared.

Practice: Timed character Cron used in conjunction with temporary file management

Vim  /usr/lib/tmpfiles.d/westos.conf              # #编写配置文件的内容
d   /westos/   777  root  root    30s

systemd-tmpfiles--create/usr/lib/tmpfiles.d/*   # #执行配置文件的内容, create/westos/touch when directory/westos/does not exist

westos/file{1..5}     # #向存放临时文件的目录内新建文件

vim/etc/cron.d/westos       # #文件方式编写定向任务  * * * *  *  * root systemd-tmpfiles--clean  /usr/lib/tmpfiles.d/*                    # #每分钟清理一次临时文件

ls-l/westos/               # #查看临时文件是否被清理

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.