Pergunta

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

Foi útil?

Solução

Just do

python FILE | at TIME > app.log

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

TIME - Your time

Outras dicas

This works on my linux box:

echo python myscript | at 10:15

Edit: stupid quoting...

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).

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top