linux系统中at命令 一次性计划任务服务

1、一次性计划任务服务顾名思义只执行一次,直接测试

复制代码
[root@linuxprobe test]# date  ## 查看系统当前日期
Mon Oct 19 12:45:10 CST 2020
[root@linuxprobe test]# at 12:48  ## 使用格式, at + 时间,表示在12:48执行命令
at> mkdir test1 test2
at> <EOT>    ## 这里使用ctrl + d 结束命令输入
job 2 at Mon Oct 19 12:48:00 2020
[root@linuxprobe test]# at -l   ## 这里列出所有额一次性计划任务服务
2       Mon Oct 19 12:48:00 2020 a root
[root@linuxprobe test]# at 12:50   ## 再创建一个一次性计划任务服务
at> echo "this is a test!"
at> <EOT>
job 3 at Mon Oct 19 12:50:00 2020
[root@linuxprobe test]# at -l  ## 查看当前系统中已经有两个一次性计划任务服务
2       Mon Oct 19 12:48:00 2020 a root
3       Mon Oct 19 12:50:00 2020 a root
[root@linuxprobe test]# atrm 3  ## 使用 atrm删除任务序号3
[root@linuxprobe test]# at -l  ## 再次查看只剩下一个计划任务服务
2       Mon Oct 19 12:48:00 2020 a root
[root@linuxprobe test]# ls
[root@linuxprobe test]# date  
Mon Oct 19 12:46:46 CST 2020
[root@linuxprobe test]# date  ## 查看系统日期
Mon Oct 19 12:48:11 CST 2020
[root@linuxprobe test]# ls  ## 已经多出两个目录,是一次性计划任务服务命令执行的结果
test1  test2
[root@linuxprobe test]# ll -h  ## 查看创建时间
total 0
drwxr-xr-x. 2 root root 6 Oct 19 12:48 test1
drwxr-xr-x. 2 root root 6 Oct 19 12:48 test2

[root@linuxprobe test]# at -l  ## 已经没有计划任务服务
[root@linuxprobe test]#

复制代码

 

2、通过 at -f shell.sh time格式执行

复制代码
[root@linuxprobe test]# ls
test.sh
[root@linuxprobe test]# cat test.sh  ## 测试脚本
#!/bin/bash
date
seq 10 > a.txt
date
[root@linuxprobe test]# date
Mon Oct 19 13:11:20 CST 2020
[root@linuxprobe test]# at -f test.sh  13:12  ## 设定时间执行
job 10 at Mon Oct 19 13:12:00 2020
[root@linuxprobe test]# at -l
10      Mon Oct 19 13:12:00 2020 a root
[root@linuxprobe test]# date 
Mon Oct 19 13:12:38 CST 2020
You have new mail in /var/spool/mail/root
[root@linuxprobe test]# ls  ## 命令已经执行
a.txt  test.sh
[root@linuxprobe test]# cat a.txt
1
2
3
4
5
6
7
8
9
10
[root@linuxprobe test]# ll -h  ## 时间戳一致
total 8.0K
-rw-r--r--. 1 root root 21 Oct 19 13:12 a.txt
-rw-r--r--. 1 root root 37 Oct 19 13:11 test.sh
复制代码

 

3、时间格式采用12进制格式

复制代码
[root@linuxprobe test]# ls
test.sh
[root@linuxprobe test]# cat test.sh
#!/bin/bash
date
seq 10 > a.txt
date
[root@linuxprobe test]# date
Mon Oct 19 13:16:47 CST 2020
[root@linuxprobe test]# at -f test.sh 01:18 PM  ## 指定下午
job 11 at Mon Oct 19 13:18:00 2020
[root@linuxprobe test]# ls
test.sh
[root@linuxprobe test]# date
Mon Oct 19 13:17:18 CST 2020
[root@linuxprobe test]# date
Mon Oct 19 13:17:59 CST 2020
[root@linuxprobe test]# date
Mon Oct 19 13:18:03 CST 2020
[root@linuxprobe test]# ls
a.txt  test.sh
[root@linuxprobe test]# ll
total 8
-rw-r--r--. 1 root root 21 Oct 19 13:18 a.txt
-rw-r--r--. 1 root root 37 Oct 19 13:11 test.sh
[root@linuxprobe test]# cat a.txt
1
2
3
4
5
6
7
8
9
10
复制代码

 

4、时间格式 n 分钟后执行

复制代码
[root@linuxprobe test]# ls
test.sh
[root@linuxprobe test]# cat test.sh
#!/bin/bash
date
seq 10 > a.txt
date
[root@linuxprobe test]# date
Mon Oct 19 13:20:32 CST 2020
[root@linuxprobe test]# at -f test.sh now+2 min
job 12 at Mon Oct 19 13:22:00 2020
[root@linuxprobe test]# ls
test.sh
[root@linuxprobe test]# date
Mon Oct 19 13:22:41 CST 2020
You have new mail in /var/spool/mail/root
[root@linuxprobe test]# ls
a.txt  test.sh
[root@linuxprobe test]# ll
total 8
-rw-r--r--. 1 root root 21 Oct 19 13:22 a.txt
-rw-r--r--. 1 root root 37 Oct 19 13:11 test.sh
[root@linuxprobe test]# cat a.txt
1
2
3
4
5
6
7
8
9
10
复制代码

 

5、时间格式n天后执行

[root@linuxprobe test]# ls
test.sh
[root@linuxprobe test]# date
Mon Oct 19 13:24:47 CST 2020
[root@linuxprobe test]# at -f test.sh now+2 day
job 14 at Wed Oct 21 13:25:00 2020

 

posted @   小鲨鱼2018  阅读(539)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示