Is there a way to determine if a python script was started by Cron? [duplicate]
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.
精彩评论