How to use Red Hat Software Collections in scripts and cron jobs

Solution Verified - Updated -

Environment

  • Red Hat Software Collections
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7

Issue

  • How to use Red Hat Software Collections in automated scripts or applications?
  • The manuals suggests only interactional stuff
# scl enable python27 bash
# scl enable python27 'python'

Resolution

  • There are several options on how to address this question and solve it. It also highly depends on the given use-case and on whether a user should only use Red Hat Software Collections for certain scripts/jobs or for all tasks it is running. Below are a couple of examples on how to address the specific use case, explaining how to enable Red Hat Software Collections within automated scripts or applications
  1. Enable Red Hat Software Collections in the user profile as per How can I make a Red Hat Software Collection persist after a reboot/logout?
  2. Adjust the script header to use #!/usr/bin/env python as the scripts interpreter definition and setup cron, enabling Red Hat Software Collections
    30 * * * * scl enable python27 <path to script>/python_script.py
  3. Call a shell script, which is executing the respective Red Hat Software Collections script and setup a cron job accordingly
#/bin/bash
python <path to script>/python_script.py
  • Setup cron calling the bash wrapper script
    30 * * * * scl enable python27 <path to script>/bash_script.sh

Root Cause

  • Red Hat Software Collections is a Red Hat offering that provides a set of dynamic programming languages, database servers, and various related packages that are either more recent than their equivalent versions included in the base Red Hat Enterprise Linux system, or are available for this system for the first time. Red Hat Software Collections does not replace the default system tools provided with Red Hat Enterprise Linux 6 or Red Hat Enterprise Linux 7. Instead, a parallel set of tools is installed in the /opt directory and can be optionally enabled per application or user with the supplied scl utility. Red Hat Software Collections are utilizing /opt as there basic installation prefix to have proper segregation between products shipped directly with Red Hat Enterprise Linux and products provided by Red Hat Software Collections.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments