Linux下 定时任务执行
单次定时任务at 与 周期定时任务cron
设置单次定时任务
at 命令设置一次定时任务
当需要再某一特定时间 执行一个任务的时候,我们使用at 命令进行设置。比如设置在某一时间发送邮件,或者在半个小时后自动关机,此时我们就可以使用at
设置任务
- 在30 分钟后输出hello
[root@VM_70_170_centos ~]# at now + 30 minutes
at> echo "hello"
at> <EOT>
job 1 at Thu Mar 4 21:30:00 2021
//在一分钟后输出hello1
[root@VM_70_170_centos ~]# at now + 1 minutes
at> echo "hello1"
at> <EOT>
job 2 at Thu Mar 4 21:01:00 2021
[root@VM_70_170_centos ~]#
- 在某个固定时间设置一个任务
[root@VM_70_170_centos ~]# at 21:10 2021-03-04
at> echo "hello2"
at> <EOT>
job 3 at Thu Mar 4 21:10:00 2021
- 第一行 :at + 定时时间
- 第二行: 要执行的命令
- 第三行 ÿ