3

I have an automated script - I mean, it runs every 10 minutes by a cronjob. The weird thing is: The file is always found and runs through it when I start the script by hand. But it gives me a lot of troubles when it runs by cron job.

these are the rights of the files:

-rw-r--r-- 1 dataloader users     181 Dec 19 12:37 Foo.after
-rwxr-xr-x 1 dataloader users   26098 Feb 16 20:56 loader.py

this is an abstract of loader.py where it checks for Foo.after:

if os.path.exists(self.customer+'.after'):
            print 'customer file exists'
            f = open(self.customer+'.after')
1
  • 2
    Most likely the script isn't running in the directory you think it is inside the cron job Commented Feb 16, 2012 at 20:16

2 Answers 2

10

The cronjob is not executing in the same directory/environment as the script.

You can address this by adjusting your cronjob:

* * * * * cd /home/yourdir; ./loader.py

OR

* * * * * /home/mc/dotasks.sh

dotasks.sh contains:

cd /home/yourdir
./loader.py
#anything else you need to do
Sign up to request clarification or add additional context in comments.

Comments

0

First check the environment configured for cron, you can dump it as a cron job itself. * * * * * env > /yourcompletepath/envtxt Now look for python version. Does it match. Look for PWD value. From here you can cd to your working folder and then use python to start your file. Ensure that the python file is terminated properly, without any blank spaces near EOF.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.