如何使用at命令设置python脚本在指定时间执行
当我将来尝试使用 cron 来执行我的 python 脚本时,我发现有一个命令,AFAIK,cron 用于定期执行,但我的场景仅在指定时间执行一次。 我的问题是如何将 python 脚本添加到 at 命令中, 还有一些用于控制 at 命令的 python 包
我的开发操作系统是 ubuntu 10.04 lucid,我的产品服务器是 ubuntu-server 10.04 lucid 版本。 事实上,我想通过python脚本将python脚本任务添加到at命令中,该文件的更改可以影响at命令添加或删除新作业
When I try to use cron to execute my python script in a future time, I found there is a command at, AFAIK, the cron is for periodically execute, but what my scenario is only execute for once in specified time.
and my question is how to add python script to at command,
also it there some python package for control the at command
My dev os is ubuntu 10.04 lucid,and my product server is ubuntu-server 10.04 lucid version.
in fact, I want through python script add python script tasks to at command, which file's change can effect at command add or remove new jobs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这适用于我的 Linux 机器:
编辑:愚蠢的引用...
This works on my linux box:
Edit: stupid quoting...
正如手册页所述,at(例如,与 cron 相反)不尊重 shebang(
#!/usr/bin/env python行)。它始终使用
/bin/sh
来运行该文件。因此,为了运行 python 脚本,您必须
按照 @bstpierre 的建议使用或创建一个附加文件
myscript.sh:
,这样就
不需要 Shebangs (但也不会造成伤害)。
As the man page says, at (as opposed to cron for example) doesn't respect shebang (the
#!/usr/bin/env python
line). It always uses/bin/sh
to run the file.So in order to run a python script you have to use either
as suggested by @bstpierre or create an additional file
myscript.sh:
and then
Shebangs are not necessary this way (but wouldn't hurt either).
输入
man at
,它会解释如何使用它。不同系统的用法会略有不同,因此这里没有必要准确地告诉您。type
man at
, it will explain how to use it. Usage will slighty differ from system to system, so there's no use to tell you here exactly.只需
更换:
FILE - 您的 .py 文件(包括 shebang)
TIME - 您的时间
Just do
replace:
FILE - Your .py file (include the shebang)
TIME - Your time