at 命令
at 一般会预装在系统中
at - v 查看at 版本
[root@localhost ~]# systemctl status atd
● atd.service - Deferred execution scheduler
Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; vendor preset:>
Active: active (running) since Wed 2023-03-15 17:26:44 CST; 3 days ago
Docs: man:atd(8)
Main PID: 1154 (atd)
Tasks: 1 (limit: 10754)
Memory: 300.0K
CPU: 11ms
CGroup: /system.slice/atd.service
└─1154 /usr/sbin/atd -f
3月 15 17:26:44 localhost.localdomain systemd[1]: Started Deferred execution sche>
lines 1-12/12 (END)
atd 与 crond 的区别
atd 是在指定时间做一次指定的任务
crond 是可以循环反复的执行定时的任务
使用at 命令将时间写入指定的文件
[root@localhost ~]# at 9:00 2023-4-15
warning: commands will be executed using /bin/sh
at> ^C[root@localhost ~]# at 9:00 2023-4-15
warning: commands will be executed using /bin/sh
at> data >> /root/testmail.txt
at> <EOT>
job 2 at Sat Apr 15 09:00:00 2023
查看crond命令
root@localhost ~]# systemctl status crond
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor prese>
Active: active (running) since Wed 2023-03-15 17:26:44 CST; 3 days ago
Main PID: 1156 (crond)
Tasks: 2 (limit: 10754)
Memory: 2.3M
CPU: 757ms
CGroup: /system.slice/crond.service
├─1156 /usr/sbin/crond -n
└─5339 /usr/sbin/anacron -s
3月 18 14:01:01 localhost.localdomain CROND[4766]: (root) CMDEND (run-parts /etc/>
3月 18 15:01:01 localhost.localdomain CROND[4804]: (root) CMD (run-parts /etc/cro>
3月 18 15:01:01 localhost.localdomain run-parts[4807]: (/etc/cron.hourly) startin>
3月 18 15:01:01 localhost.localdomain run-parts[4813]: (/etc/cron.hourly) finishe>
3月 18 15:01:01 localhost.localdomain CROND[4803]: (root) CMDEND (run-parts /etc/>
3月 19 12:01:01 192.168.9.128 CROND[5326]: (root) CMD (run-parts /etc/cron.hourly)
3月 19 12:01:01 192.168.9.128 run-parts[5329]: (/etc/cron.hourly) starting 0anacr>
3月 19 12:01:01 192.168.9.128 anacron[5339]: Anacron started on 2023-03-19
3月 19 12:01:01 192.168.9.128 anacron[5339]: Will run job `cron.daily' in 21 min.
3月 19 12:01:01 192.168.9.128 anacron[5339]: Jobs will be executed sequentially
lines 1-21/21 (END)
使用crond 命令来进行周期性命令
[root@localhost ~]# crontab -e
0 4 ***