[wplug] executing a python script from crontab
Bryon Gill
bgtrio at yahoo.com
Fri May 26 00:20:36 EDT 2006
Just fyi, you can also use the os.chdir() function to put yourself wherever you
want to be when your script is executed.
http://docs.python.org/lib/os-file-dir.html
Bryon
On Fri, 26 May 2006, Patrick Wagstrom wrote:
>> <snip>
>> Traceback (most recent call last):
>> File "/root/scripts/boxster_school_smtp.py", line 19, in ?
>> mssg = open('mssg.txt', 'r').read()
>> IOError: [Errno 2] No such file or directory: ' mssg.txt'
>> </snip>
>
> Your problem isn't with your python script at all, rather it's with the
> location you're executing the script form. One of the tricky things
> with cron is that you need to make sure you're in the correct directory.
> What directory does mssg.txt reside in? If it's supposed to be in /root
> then you'll want to change the line to:
>
> */5 * * * cd /root && /usr/local/bin/python /root/scripts/boxster_school_smtp.py
>
> Another option might make it read in the value of sys.argv[1] for the
> location of the file instead. Then you'll call:
>
> import sys
> mssg = open(sys.argv[1], 'r').read()
>
> And in your crontab insert something like:
>
> */5 * * * /usr/local/bin/python /root/scripts/boxster_school_smtp.py [LOCATION OF MSSG.TXT]
>
> --Patrick
>
>
> _______________________________________________
> wplug mailing list
> wplug at wplug.org
> http://www.wplug.org/mailman/listinfo/wplug
>
More information about the wplug
mailing list