Python and Cron

Greg Lindstrom gslindstrom at gmail.com
Fri Sep 7 21:09:06 CEST 2007


> Can you post the Python script?


Not the whole thing; it's quite long.  But here's the relevant parts.  We're
using the ado database interface into postgres (that's what the
results.EOFis all about)

output_file = file(output_path, 'w')   # output_path =
/my_path/data/work/my_file.txt
while not results.EOF:
row = results.GetRowAssoc(upper=0)
output_file.write(row['data'])
results.MoveNext()
output_file.close()
debug('Total Bytes Written: %d' % total_bytes)

new_path = None
if total_bytes > 0:   new_path = output_path.replace('/work/', '/')
else:                     new_path = output_path.replace('/work/',
'/empty/')

debug('Original Path [%s]'%output_path)   # new_path =
/my_path/data/my_file.txt
debug('     New Path [%s]'%new_path)      # new_path =
/my_path/data/empty/my_file.txt


The original code looked like this (worked from command line, failed with
cron)

os.rename(output_path, new_path)

But since that didn't work and I could create a new file, I tried this as a
work around

output_file = file(new_path, 'w')
for line in file(output_path):
output_file.write(line)
output_file.close()

The interesting/infuriating thing is that the second method also fails; that
is, the file is not moved to the data directory or the "empty"
directory...it remains in the "work" directory after the cron job
completes.  If I run the same routine from the command like (after su'ing to
the edith user) it runs and moves the file to the appropriate directory.

I am going to see if we can get the email routing set up (we run over 100
cron jobs daily so I'm not sure I want it on too long) to see if it will
tell me anything.


Thanks for your time and effort
--greg



What's the name of the original file, and what are you trying to rename
> it to? I'm wondering if you are deriving the new name from something,
> and that thing is failing from within the cronjob for some reason.
> Perhaps the new name contains a complete path in one of the cases but
> not in the other...
>
> Edith should be getting email (if email routing is set up correctly) if
> the job is failing or producing output. Specifically, perhaps she's
> getting Python tracebacks and not telling you... :)
>
>
>
> --
> pkm ~ http://paulmcnett.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070907/dcd2b2ba/attachment.html>


More information about the Python-list mailing list