title: scl enable python27 bash
body: <p>I've hit a snag with a shell script intended to run every 30 minutes in cron on a Redhat 6 server. The shell script is basically just a command to run a python script. </p>
  
  <p>The native version python on the server is 2.6.6 but the python version required by this particular script is python 2.7+. I am able to easily run this on the command line by using the "scl" command (this example includes the python -V command to show the version change):</p>
  
  <pre><code>$ python -V
  Python 2.6.6
  $ scl enable python27 bash
  $ python -V
  Python 2.7.3
  </code></pre>
  
  <p>At this point I can run the python 2.7.3 scripts on the command line no problem.</p>
  
  <p>Here's the snag.</p>
  
  <p>When you issue the <code>scl enable python27 bash</code> command it starts a new bash shell session which (again) is fine for interactive commandline work. But when doing this inside a shell script, as soon as it runs the bash command, the script exits because of the new session.</p>
  
  <p>Here's the shell script that is failing:</p>
  
  <pre><code>#!/bin/bash
  cd /var/www/python/scripts/
  scl enable python27 bash
  python runAllUpserts.py &gt;/dev/null 2&gt;&amp;1
  </code></pre>
  
  <p>It simply stops as soon as it hits line 4 because "bash" pops it out of the script and into a fresh bash shell. So it never sees the actual python command I need it to run.</p>
  
  <p>Plus, if run every 30 minutes, this would add a new bash each time which is yet another problem.</p>
  
  <p>I am reluctant to update the native python version on the server to 2.7.3 right now due to several reasons. The Redhat yum repos don't yet have python 2.7.3 and a manual install would be outside of the yum update system. From what I understand, yum itself runs on python 2.6.x.</p>
  
  <p>Here's where I found the method for using scl</p>
  
  <p><a href="http://developerblog.redhat.com/2013/02/14/setting-up-django-and-python-2-7-on-red-hat-enterprise-6-the-easy-way/">http://developerblog.redhat.com/2013/02/14/setting-up-django-and-python-2-7-on-red-hat-enterprise-6-the-easy-way/</a></p>