linux 通过at命令创建任务

以Ubuntu为例演示at命令的使用

/home/fnngj/test/目录下创建file.py 文件

#!/usr/bin/python
#coding=utf-8
f=open('f.txt','w')
f.write('hello world!!')
f.close()


以写('w')操作打开当前目录下的f.txt 文件(没有此文件会自动创建),向文件中写入‘hello world!’,
然后close()关闭文件。
通过at 执行创建的file.py 程序。


fnngj@fnngj-VirtualBox:~/test$ at now+5 minutes
warning: commands will be executed using /bin/sh
at> python /home/fnngj/test/fiele.py
at> <EOT> Ctrl+d 保存退出
job 17 at Wed Jan 8 17:56:00 2014
now+5 minutes 表示当前时间,5分钟之后执行
python /home/fnngj/test/fiele.py 要执行的文件,python 命令,文件要完整的路径
Ctrl+d 保存退出


查看创建的任务
fnngj@fnngj-VirtualBox:~/test$ at -l
18 Wed Jan 8 17:56:00 2014 a fnngj
fnngj@fnngj-VirtualBox:~/test$ atq
10 Wed Jan 8 12:57:00 2014 a fnngj
at -l / atq 两个命令查看at 创建的任务。


删除已经设置的任务
fnngj@fnngj-VirtualBox:~/test$ at -l
10 Wed Jan 8 12:57:00 2014 a fnngj
fnngj@fnngj-VirtualBox:~/test$ atrm 10
10 是任务的“编号”,atrm 用于删除已经创建的任务

http://fnng.cnblogs.com 209
启动atd 进程
linux 一般默认会启动atd 进行

at 命令指定时间的方式
绝对计时方法:
midnight noon teatime
hh:mm [today]
hh:mm tomorrow
hh:mm 星期
hh:mm MM/DD/YY
相对计时方法:
now+n minutes
mow+n hours
now+n days
用法:
指定在今天下午17:30执行某命令(假设现在时间是下午14:30,2014年1月11日)
命令格式:
at 5:30pm
at 17:30
at 17:20 today
at now+3 hours
at now+180 minutes
at 17:30 14.1.11
at 17:30 1.11.14
博客园---虫师
http://fnng.cnblogs.com 210
查看f.txt 文件内容
fnngj@fnngj-VirtualBox:~/test$ ls
f.txt~ f.txt open.py open.py~
fnngj@fnngj-VirtualBox:~/test$ cat f.txt
hello world!!

 

转载于:https://www.cnblogs.com/bokeyuan228/p/7115026.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值