shell - Python Script not running in crontab calling pysaunter -


i have read multiple posts , many articles detailing scipts in cron job need keep environment variables necessary run inside script due opening of shells within cron. situation unique in path variables being set discussed, in turn call pysaunter python egg using subprocess.call(), seems break down there. causes whole process break in cron job.

for clarity, here steps refer to:

1) cronjob calls run_test.py -n foo 2) run_test.py sets environment variables correctly  (cur_shell_path=sys.path (converted proper path string, not shown here)  my_env= os.environ.copy()  my_env["path"] = my_env["path"] + cur_shell_path) 3) run_test.py calls subprocess.call("pysaunter -m foo -v", env=my_env, shell=true) 

the output of step 3 shows finding egg , starts load necessary modules pysaunter, breaks when attempting find directory used modify pysaunter. error reads :

importerror: no module named helpers 

i have attempted adding path environment multiple times never seems find directory contains helpers.py. command pysaunter -m foo -v works when called interactive shell.

i couldn't find on pysaunter, assume pysaunter specifics unneccessary here. if know more pysaunter, please let me know if require more information. not sure share.

i have read many posts discussing ability change default behavior of shell editing .profile/.bash_profile. attempted find place make path variables globally accessible, couldn't find anything. not sure how done, , may fix problem, if know please let me know.

final note, running on mac 10.7.5.

after trial , error, , many, many stackoverflow.com articles , other tutorials online, , of perl script found did similar, able figure out needed done work.

here steps making sure set correctly:

  1. make sure have variables need in pythonpath (found here , here, , more info. go here) inside .profile or .bash_profile shell want test script in make sure works.

  2. edit crontab include directories needed run script in cron job (found here , here).

    a) sure include root directory in path variable (.) explained here. basically, if running executable command needs able find root or directory executable stored , these: (/sbin:/bin:/usr/sbin:/usr/bin).

  3. in crontab file, create cronjob change current directory directory have run script before (e.g., /users/user/documents/foo).

    a) following:

    * * * * cd /users/user/documents/foo; bar -l dosomething -v  
  4. since problem dealt calling executable, necessary note there multiple ways of writing python script run (though in process of discovery learned works call made using subprocess in cron).

    the first method looks this:

    ... #some script calls my_env = os.environ.copy() my_env["pythonpath"] = "{}:{}".format(os.environ["path"] ,"<path want include>") os.chdir("<path/to/desired/directory>") subprocess.popen(<call_as_string>, env=my_env, shell=true) 

    and second looks this:

    ... #some script calls os.environ["pythonpath"] = "{}:{}".format(os.environ["path"] ,"<path want include>") os.chdir("<path/to/desired/directory>") subprocess.popen(<call_as_list_of_arguments) 

    since executable needed path helpers directory included in shell called from, necessary pass environment variable executable explained here. found, though, modifying path variable in environment didn't work cron job, setting pythonpath did. read here path variable used shell executables, new shell inside cronjob need pass shell pythonpath new python modules. (this explained in python docs.)

    the differences between 2 different methods explained in subprocess documentation cited in question, tutorial on module can found here.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -