atd
单次计划任务:atd
语法:
atd 时间
服务:atd 开启状态
启动:systemctl restart atd
开机自启:systemctl enable atd
举例
举例1(小时和分钟来执行):
[root@ip-9-0-1-235 hdlefs]# at 16:15
at> echo "hello word!" > /var/www/html/hello.html
at> <EOT>
job 1 at Tue Jun 21 16:15:00 2022
举例2(年月份-小时分钟来执行):
[root@ip-9-0-1-235 html]# at 16:18 2022-6-21
at> echo "hello word 1!" >> /var/www/html/hello.html
at> <EOT>
job 2 at Tue Jun 21 16:18:00 2022
[root@ip-9-0-1-235 html]# cat hello.html
hello word!
hello word 1!
举例3(当前时间+多少时间来执行):
[root@ip-9-0-1-235 html]# at now +10min
at> echo "hello word 2!" >> /var/www/html/hello.html
at> <EOT>
job 3 at Tue Jun 21 16:32:00 2022
命令
查看系统中有多少计划任务:at -l
计划任务存放的目录:ll /var/spool/at/
删除计划任务:atrm 编号(at -l即可查看编号)
周期性计划任务:
配置文件:vim /etc/crontab
查看状态:systemctl status crond
启动服务:ystemctl restart crond
开机自启:systemctl enable crond
/etc/crontab文件解析:
* * * * * command
分 时 日 月 星 命令
crond存放的命令和脚本在
/etc/cron.d/
/etc/cron.daily/ 每天
/etc/cron.deny
/etc/cron.hourly/ 每小时
/etc/cron.monthly/ 每月d
/etc/cron.weekly/ 每周
针对用户级别的计划任务:
对于root用户:
命令:
crontab -e 创建一个计划任务
crontab -l 显示
crontab -r 删除计划任务