How to use at command to set python script execute at specified time

倾然丶 夕夏残阳落幕 提交于 2021-02-04 19:55:06

问题


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


回答1:


Just do

python FILE | at TIME > app.log

replace: FILE - Your .py file (include the shebang)

TIME - Your time




回答2:


This works on my linux box:

echo python myscript | at 10:15

Edit: stupid quoting...




回答3:


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

echo python myscript.py | at 10:15

as suggested by @bstpierre or create an additional file

myscript.sh:

python myscript.py

and then

at -f myscript.sh at 10:15

Shebangs are not necessary this way (but wouldn't hurt either).




回答4:


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.



来源:https://stackoverflow.com/questions/3774772/how-to-use-at-command-to-set-python-script-execute-at-specified-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!