1

I have a very basic python script to run through crontab for every minutes.

The Script

filed = open('test.txt','a')

Crontab

* * * * * /to path the file/job.py

It should work, but i have not been able to see the results. So, what could be the problem ?

2
  • @MartijnPieters is correct, but doesn't your cron send you emails when it fails? What do those emails say? Commented Jan 28, 2013 at 23:44
  • Usually these problems are because the env for your shell is different to cron. It can be the pwd as Martijn says. Another possibility would be your $PATH is different. You need to give us some more clues to work out the actual problem Commented Jan 29, 2013 at 0:03

1 Answer 1

6

You need to open text.txt using an absolute path; the crondaemon may well be using different path from what you expect:

filed = open('/home/john/Desktop/test.txt','a')
Sign up to request clarification or add additional context in comments.

1 Comment

+1 More flexible may be the following: import os; filed = open(os.path.join(os.path.dirname(__file__), 'test.txt'), 'a'), which basically does what you do, but creates absolute path by building it dynamically for the file located in the same directory as Python script.

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.