linux - Wrong path results the python program runs using crontab -
i have script in python under linux needs determine current working directory. part of programme is:
import os cwd = os.getcwd() print cwd when run programme gives me right answer:
/home/johny/lst/ct but when run using crontab, gives me this:
/home/johny even when set in deeper folders, same path results. know can problem?
cron sets home directory. if need script run in particular directory consider using like
import os os.chdir(os.path.dirname(os.path.abspath(__file__))) at top of script although script should not care it's run from. file paths in script should relative script, using like:
scriptdir = os.path.dirname(os.path.abspath(__file__)) mypath = os.path.join(scriptdir, 'data', 'mfile.dat') ... etc ... python linux python-2.7 cron crontab
No comments:
Post a Comment