Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong path results the python program runs using crontab

I have a script in python under Linux that needs to determine the current working directory. The part of program that does this is:

import os
cwd = os.getcwd()
print cwd

When I run the program it gives me the right answer:

/home/johny/LST/CT

But when I run it using crontab, it gives me this:

/home/johny

Even when I put it in deeper folders, the same path results. Does anybody know what can be the problem?

like image 552
f.ashouri Avatar asked Feb 18 '23 12:02

f.ashouri


1 Answers

In your crontab file do:

1 0 * * * cd /home/johny/LST/CT; python your_script.py
like image 65
mechanical_meat Avatar answered Feb 20 '23 10:02

mechanical_meat