开发者

Is there a way to determine if a python script was started by Cron? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How can I determine if a python script is executed from cr开发者_运维知识库ontab?

Is there a way to determine if a python script was started by cron or not?


Not per se, but you could set an environment variable in the crontab and check it in the script.

* * * * * CRONRUN=y /srv/cron/foo.py

...

if 'CRONRUN' in os.environ:
   ...


Without knowing what your script does, I can give a couple of suggestions.

If the script runs then terminates, have the script log its start and end time in a log file.

If the script is a process, or runs as a daemon, and you are using cron to start the script on a reboot (depending on the cron daemon you are using), you can use the program ps to view a snapshot of the current processes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜