1. System Delay Task
1.at command
at命令发起的延时任务都时一次性的
at + time[carriage return]
Instruction 1[Carriage Return]
Instruction 2[Carriage Return]
... Enter
Press Ctrl+d to initiate the action
Example 1:
[[email protected] ~]# at 11:11 ##设定人物执行时间(当前用户是谁就是谁发起的任务)at> rm -fr /mnt/* ##延时动作(删除/mnt下所有内容)at> ##ctrl+d发起动作
Example 2:
[[email protected] ~]# at now+1min ##设定人物执行时间为1分钟后at> rm -fr /mnt/* ##延时动作at> ##ctrl+d表示发起动作
2. Some AT commands
at -l | atq #查看当前任务atrm | at -d #取消指定任务at -c #查看任务内容at now+1min #延迟一分钟at -f file #延迟执行文件中的内容at -m #延迟命令没有输出时仍然发送邮件给执行者at -M #延迟命令有输出时但不发送邮件给执行者
When the task has output, the output is sent to the initiator of the at character in the form of a message.
View message: Mail-u root
Then press the number selection to view the first few messages and press Q to exit.
Black and white list at command
/etc/at.deny ##用户黑名单,在此名单中出现的用户不能执行at命令/etc/at.allow ##用户白名单,名单默认不存在,但名单一旦出现,黑名单失效,且普通用户不能执行at ##默认系统所有用户不能执行at,只有在名单中出现的用户可以使用at命令
2. System timing Tasks
定时任务时永久的定时任务程序crond,在系统中每分钟做任务扫描系统控制crontab的服务 crontab.service ##当程序开启时定时任务生效
1. Initiation Mode one: crontab command
crontab -u username -e [回车] ##用户发起任务crontab -u username -r [回车] ##删除任务crontab -u username -l [回车] ##查看任务
Input execution Task: Time + action
* * * * *这五个*号分别表示分钟、时钟、日,月、周几
For example:
* * * * * 动作命令 #每分钟执行一次* * */2 * * 动作命令 #每隔两天* 08-17/2 * * * 动作命令 #8点到17点每隔2小时执行一次*/2 09-17 * * * 动作命令 #每天9点到17点美隔2分钟执行一次*/2 09-17 * * 5 动作命令 #每周周五9点到17点每2分钟执行一次*/2 09-17 1 3,5 5 动作命令 #3月和5月的每周周五和每月1号9点到17点美2分钟执行一次
Scheduled Task store Files:
/var/spool/cron/directory, a file that records the scheduled tasks initiated by each user
2. Initiation Mode II: File Settings
Edit New file: Vim/etc/cron.d/filename
* * * * * root rm -fr /mnt/* ##超级用户每分钟清理一次/mnt
In the/etc/directory there are cron.daily, cron.hourly, cron.monthly, cron.weekly these files
Write commands under these files, which are executed on a daily, hourly, or monthly, or weekly basis.
Black and white list of CRONTAB commands
/etc/cron.deny ##用户黑名单,在此名单中出现的用户不能执行crontab命令 /etc/cron.allow ##用户白名单,名单默认不存在,但名单一旦出现,黑名单失效,只有在名单中的用户可以,并且/etc/at.deny失效 ##这两个名单都不会影响在/etc/cron.d/目录中定时任务的执行。
3. Management of temporary system files
A temporary file is generated by the service in the system during normal operation
编辑文件: vim /usr/lib/tmpfiles.d/westos.conf ##系统中临时文件的配置
Description
d /mnt/westos 777 root root 10s(1)文件类型 (2)文件名称 (3)文件权限 (4)文件所有人 (5)文件所有组 (6)文件存在时间
Execute command:
systemd-tmpfiles --create /usr/lib/tmpfiles.d/* ##执行临时文件配置systemd-tmpfiles --clean /usr/lib/tmpfiles.d/* ##清理临时文件
Linux (Radhat) Basic learning-delay tasks and scheduled tasks