Script runs manually, but cron fails

B

Bryan

I have a backup script that runs fine when I run it manually from the
command line. When I run it with cron, the script stops running at
random points in the source code.

The script calls rsync with the subprocess module, which in turn uses
ssh to backup files from a box on my lan. It also uses the atexit
module to always run a certain piece of cleanup code when the script
exits. However, this piece of code is never called when I use cron to
run the script, but a ps -A command also does not show the python
process so I know the script is dead. The log files generated by the
script all show rsync as completing, but then the logging gets cutoff
at random places when the script dies after that point. I am not
getting any email from cron complaining of an error either.

The script runs fine in my bash shell, what could cron be doing to
interfere?
 
E

Emile van Sebille

On 7/24/2009 2:11 PM Bryan said...
The script runs fine in my bash shell, what could cron be doing to
interfere?

It's likely environmental -- make sure you're starting with the same
path, etc. Sometimes I'll create a sell script by env'ing to a bash
script file and append the actual command to execute, chmod a+x the
script and put that in the cron file. Then strip out variables until
you find the missing culprit.

HTH,

Emile
 
B

Bryan

I have a backup script that runs fine when I run it manually from the
command line.  When I run it with cron, the script stops running at
random points in the source code.

The script calls rsync with the subprocess module, which in turn uses
ssh to backup files from a box on my lan.  It also uses the atexit
module to always run a certain piece of cleanup code when the script
exits.  However, this piece of code is never called when I use cron to
run the script, but a ps -A command also does not show the python
process so I know the script is dead.  The log files generated by the
script all show rsync as completing, but then the logging gets cutoff
at random places when the script dies after that point.  I am not
getting any email from cron complaining of an error either.

The script runs fine in my bash shell, what could cron be doing to
interfere?

This script works when I run it at home, and I think it is because I
don't use rsync's ability to backup over ssh. The working script at
home simply backs up the local machine to a mounted external hard
drive. So when I run a python script that calls rsync to work over
ssh, cron is screwing things up. Can anyone recommend where I should
report this behavior? Should I email the author of cron directly, I
don't see a group/address specifically for cron bugs.
 
J

J Kenneth King

Bryan said:
I have a backup script that runs fine when I run it manually from the
command line. When I run it with cron, the script stops running at
random points in the source code.

The script calls rsync with the subprocess module, which in turn uses
ssh to backup files from a box on my lan. It also uses the atexit
module to always run a certain piece of cleanup code when the script
exits. However, this piece of code is never called when I use cron to
run the script, but a ps -A command also does not show the python
process so I know the script is dead. The log files generated by the
script all show rsync as completing, but then the logging gets cutoff
at random places when the script dies after that point. I am not
getting any email from cron complaining of an error either.

The script runs fine in my bash shell, what could cron be doing to
interfere?

Double check nothing is writing to stdout/stdin

Some cron's don't mind, but I always squelch output because some do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top