linux - Cron not running Python script is script not in home folder -
i know cron capricious , trying figure out how deal on linux.
i have following test_cron.py
executable python script testing cron :
#!/usr/bin/env python import os os.makedirs('test_cron_dir') f = open('test_cron_dir/test_file','w') f.write('stuff') f.close()
i added 2 lines crontab run script in 2 different folders :
* * * * * python /home/me/test_cron.py * * * * * python /home/me/some_folder/test_cron.py
the problem : cron runs test_cron.py
script located in /home/me/
not run 1 located in /home/me/some_folder/
. have changed paths in script absolute paths not change situation. also, have tried use root crontab , not change anything.
can please shine light of knowledge , experience on me ? lot.
cron running crontab(5) entries home directory of user.
you need change appropriately directory i.e. call chdir(2) syscall (either thru cd
shell builtin, or inside python script using os.chdir).
you should query current directory (using getcwd(3), or pwd
command, or os.getcwd in python) in script.
also check path
if running commands.
Comments
Post a Comment