Linux operation and maintenance - regular tasks and task delay

Why delay the timing of the task?

Many operation and maintenance tasks are completed in the morning, if operation and maintenance engineers are working every day in the morning, then before long, operation and maintenance engineers and hung up! So the task of learning the timing of the delay is necessary.

In the fall of strokes [19 Dajiang operation and maintenance engineers pen questions]

Between at 6:00 on November -12 o'clock every morning, every two hours to execute the script httpd.sh

* 6-12/2 * 11 *  sh httpd.sh

A timing task

1.crond regular tasks Service

2.crond set way

① Command mode setting: regular user level task

crontab -u root -e ##设定
crontab -u root -l ##查看
crontab -u root -r ##删除
/var/spool/cron/root ##任务存储位置

Time task

分钟 小时 日 月 周系统命令|脚本
08-17 * * * * 		##每天每小时08分-17分
08-17 * * * 3,5 	##每周3和周五每小时08分-17分
08-17/2 * * * 3,5 	##每周3和周五每小时08分-17分时间段每隔2分钟
08-17/2 10 * * 3,5 	##每周3和周五10点08分-17分时间段每隔2分钟
08-17/2 10 5 * 3,5 	##每周3和周五及每月5号10点08分-17分时间段每隔2分钟
08-17/2 10 5 3 3,5 	##3月每周3和周五及3月5号10点08分-17分时间段每隔2分钟

② profile is set: The system-level cron, only the super user can operate

/etc/cron.d 			##系统级别cron设定文件存放路径
vim /etc/cron.d/westos 	##cron设定文件
时间 用户动作
* * * * * root rm -fr /mnt/*
/etc/cron.daily/ 		##每天任务
/etc/cron.hourly/ 		##每小时任务
/etc/cron.monthly/ 		##每月任务
/etc/cron.weekly/ 		##每周执行动作

3. crond user level control settings

vim /etc/cron.deny 		##cron用户控制黑名单,此名单中的人不能执行cron命令
vim /etc/cron.allow 	##cron白名单,此文件默认不存在
						##当此文件存在时cron.deny不生效
						##当此文件存在,系统普通用户默认不能执行cron,只有在名单中才可以

II. Delay task

1. delayed tasks initiated

at 10:10
> rm -fr /mnt/* 	##执行内容
>[ctrl]+[d] 		##任务发起
at -l 				##查看任务队列
at -c 任务号			##查看任务内容
at -r 任务号			##取消任务

2. When the output delay task, the task output is sent to the originator of the mailbox in the mail

yum install mailx postfix
systemctl start postfix
systemctl enable postifx
mail -u root 		##查看root用户的邮件
No mail for root 	##root用户没有邮件
>  /var/mail/root 	##清空root邮件
at 10:30			
>timedatectl 		##此命令有输出但不会显示到字符设备中
					##此命令输出会用邮件发送给at发起人
[root@rhel8_node1 ~]# mail -u root
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/root": 1 message 1 new
>N 1 root Sat Feb 22 10:27 27/1226 "Output from
your job " 			##at输出邮件
& 1				    ##输入邮件编号查看
&q 					#退出

3.at control commands

/etc/at.deny 	##at控制黑名单,此名单中的人不能执行at
/etc/at.allow 	##此文件默认不存在
				##当此文件存在/etc/at.deny不生效
				##当此文件存在系统普通用户默认不能执行at,只有在名单中的人可以
Published 113 original articles · won praise 132 · views 30000 +

Guess you like

Origin blog.csdn.net/chaos_oper/article/details/104454806