atd和crond两个任务管理程序的区别
atd
是定时任务,在指定时间只执行一次任务。
crontab
是周期任务,每到指定时间执行一次任务
指定在2023/04/15 09: 00将时间写入testmail.txt文件中
[root@server bin]# date -s "2023-04-15 8:57"
2023年 04月 15日 星期六 08:57:00 CST
[root@server bin]# at 9:00 2023-04-15
warning: commands will be executed using /bin/sh
at> /bin/date >> /root/testmail.txt
at> <EOT>
job 2 at Sat Apr 15 09:00:00 2023
#达到指定时间
[root@server ~]# date
2023年 04月 15日 星期六 09:03:04 CST
[root@server ~]# ls
公共 视频 文档 音乐 anaconda-ks.cfg testmail.txt
模板 图片 下载 桌面 roottestmail.txt
[root@server ~]# vim ./testmail.txt
检查文件
指定每天凌晨4: 00将该时间点之前的日志信息备份到个目录下 (/ar/lg/messages ),备份后日志文件名显示格式logfileYY-MM-DD HH-MM
[root@server log]# crontab -e
crontab: installing new crontab
[root@server messages]# crontab -l
0 4 * * * /bin/cp /var/log/messages /ar/lg/messages/"logfile`date +"\%Y-\%m-\%d \%H-\%M"`"
#测试
[root@server messages]# date -s "2023-5-22 3:59:40"
2023年 05月 22日 星期一 03:59:40 CST
[root@server messages]# date
2023年 05月 22日 星期一 03:59:57 CST
[root@server messages]# ll
总用量 4
-rw------- 1 root root 1736 5月 22 04:00 'logfile2023-05-22 04-00'