Cron job is not recognizing environment variables

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Cron job is not recognizing environment variables

  • Creator
    Topic
  • #52940
    Jon Blanchard
    Participant

    This is for Red Hat Enterprise Linux running bash 3.2.25(1) and CL 5.6, rev patch 2

    I created a .sh file to collect thread statistics for the test site during our hospital conversion project.  The shell file is supposed to read the value of the $HCIROOT environment variable at the beginning; it isn’t, so the value of all derived vars are missing what should be there. The remainder of the shell script runs as it should, but without accomplishing anything.

    The crontab entry for the script is

    Code:

    00 21 * * * /home/hci/getstats2.sh

    Is there another method that I should be using?  The $ format is used by another cron job that runs successfully every night, so what do I need to do get the shell script to use it?

    Thanks in advance for your response.

    Migration Consultant
    Coffee Regional Medical Center
    Eastern Time Zone

Viewing 4 reply threads
  • Author
    Replies
    • #76004
      James Cobane
      Participant

      John,

      I’m assuming that this is scheduled under the ‘hci’ user’s cron.  You can try doing a setroot and setsite (if applicable) before running your script:

      00 21 * * * setroot;setsite mysite;/home/hci/getstats2.sh

      Hope this helps.

      Jim Cobane

      Henry Ford Health

    • #76005
      Chuck McKenna
      Participant

      We have a single script that sets the root. We import that into any script that we run from cron.

      The first thing that happens in the script is to set the variables. If you run it from the command line as hci, it just sets the root again. No harm done. This allows us to migrate scripts from our test site to our production site with no changes.

    • #76006
      Steve Carter
      Participant

      Another option that may work for you:

      If hci’s profile sets the environment that you need, you can try the following:

      00 21 * * * (. /home/hci/.profile ;/home/hci/getstats2.sh)

      –Assuming that is the location of hci’s profile.

      Hope this helps.

      Steve

    • #76007
      Jon Blanchard
      Participant

      Thank you all!

      I will try these out and let you know the results.

      Migration Consultant
      Coffee Regional Medical Center
      Eastern Time Zone

    • #76008
      Jon Blanchard
      Participant

      Found the answer, and it was quite a bit simpler than I thought:

      Migration Consultant
      Coffee Regional Medical Center
      Eastern Time Zone

Viewing 4 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10