[wplug] executing a python script from crontab

Daniel McQuay simplebob at gmail.com
Fri May 26 00:51:29 EDT 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
>   
actually i have my mssg.txt file in the same place i have my 
boxster_school_smtp.py script. is that what you meant by that?
> 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()
>   
not quite sure what mssg = open(sys.argv[1], 'r').read() but i will give 
it a try.
> And in your crontab insert something like:
>
> */5 * * * /usr/local/bin/python /root/scripts/boxster_school_smtp.py [LOCATION OF MSSG.TXT]
>   
i changed this ill let you know what happens
> --Patrick
>
>
> _______________________________________________
> wplug mailing list
> wplug at wplug.org
> http://www.wplug.org/mailman/listinfo/wplug
>
>   
thanks for the help,

-- 
Daniel McQuay
simplebob at gmail.com
boxster.homelinux.org
814.825.0847



More information about the wplug mailing list