cron - scl enable python27 bash -


i've hit snag shell script intended run every 30 minutes in cron on redhat 6 server. shell script command run python script.

the native version python on server 2.6.6 python version required particular script python 2.7+. able run on command line using "scl" command (this example includes python -v command show version change):

$ python -v python 2.6.6 $ scl enable python27 bash $ python -v python 2.7.3 

at point can run python 2.7.3 scripts on command line no problem.

here's snag.

when issue scl enable python27 bash command starts new bash shell session (again) fine interactive commandline work. when doing inside shell script, runs bash command, script exits because of new session.

here's shell script failing:

#!/bin/bash cd /var/www/python/scripts/ scl enable python27 bash python runallupserts.py >/dev/null 2>&1 

it stops hits line 4 because "bash" pops out of script , fresh bash shell. never sees actual python command need run.

plus, if run every 30 minutes, add new bash each time yet problem.

i reluctant update native python version on server 2.7.3 right due several reasons. redhat yum repos don't yet have python 2.7.3 , manual install outside of yum update system. understand, yum runs on python 2.6.x.

here's found method using scl

http://developerblog.redhat.com/2013/02/14/setting-up-django-and-python-2-7-on-red-hat-enterprise-6-the-easy-way/

doing in 1 heredoc in scl environment best option, imo:

scl enable python27 - << \eof cd /var/www/python/scripts/ python runallupserts.py >/dev/null 2>&1 eof 

another way run second command (which 1 uses python) in scl environment directly:

cd /var/www/python/scripts/ scl enable python27 "python runallupserts.py >/dev/null 2>&1" 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -