CRON on RedHat not working as expected

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf CRON on RedHat not working as expected

  • Creator
    Topic
  • #54596
    Todd Horst
    Participant

      We are moving from aix to redhat. I converted a shell script with only minor changes and now its working as expected. But when i put it in cron it wont run. I know its because of the environment cron runs in, but cannot find out exactly what to do:

      This works on aix

      Code:

      0,15,30,45 * * * * setroot && $HCIROOT/usercmds/intmon.sh 2>&1

      Although I’ve tried a million things, this is what i currently have on RedHat

      Code:

      SHELL=/bin/ksh

      PATH=/qdxiprod/cis6.1/integrator/physician1/bin:/qdxiprod/cis6.1/integrator/physician1/scripts:/qdxiprod/cis6.1/integrator/bin:/qdxiprod/cis6.1/integrator/contrib:/qdxiprod/cis6.1/integrator/sbin:/qdxiprod/cis6.1/integrator/dbms/bin:/qdxiprod/cis6.1/integrator/tcl/bin:/qdxiprod/cis6.1/integrator/clgui/bin:/qdxiprod/cis6.1/integrator/clgui/java/bin:/qdxiprod/cis6.1/integrator/usercmds:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/hci/bin:/usr/bin/X11:/sbin:.:/usr/local/bin:/usr/local/scripts:/bin:/home/hci/bin

      LIBPATH=/qdxiprod/cis6.1/integrator/clgui/java/bin:/qdxiprod/cis6.1/integrator/clgui/java/bin/classic:/qdxiprod/cis6.1/integrator/lib:/qdxiprod/cis6.1/integrator/bin:/qdxiprod/cis6.1/integrator/tcl/lib:/qdxiprod/cis6.1/integrator/dbms/lib:/qdxiprod/cis6.1/integrator/lib/Connect7.1/lib:/usr/lib:/lib:/shlib:/usr/shlib

      CL_INSTALL_DIR=/qdxiprod/cis6.1
      ROOT=$CL_INSTALL_DIR/integrator

      MAILTO=thorst2@wellspan.org
      HCIROOT=/qdxiprod/cis6.1/integrator
      KSHLIB=/qdxiprod/cis6.1/integrator/kshlib
      HCIVERSION=6.1

      * * * * * eval $HCIROOT/sbin/hcisetenv -root ksh $HCIROOT physician1 && $KSHLIB/setroot $HCIROOT && $KSHLIB/setsite physician1 && showroot

      As you can see, our default is bash, and i switch that to ksh.

      I tried to mimic the path that is there when i log in as hci

      Set the mailto so that i receive the logs via email

      When i run this i get the following:

      Code:

      unset HCIREMOTE;
      unset HCIMASTERSITE;
      HCIROOT=’/qdxiprod/cis6.1/integrator’; export HCIROOT; LD_LIBRARY_PATH=’/qdxiprod/cis6.1/integrator/clgui/java/lib/i386:/qdxiprod/cis6.1/integrator/clgui/java/lib/i386/server:/qdxiprod/cis6.1/integrator/lib:/qdxiprod/cis6.1/integrator/bin:/qdxiprod/cis6.1/integrator/tcl/lib:/qdxiprod/cis6.1/integrator/dbms/lib:/qdxiprod/cis6.1/integrator/lib/Connect7.1.2/lib:/usr/lib:/lib:/shlib:/usr/shlib’; export LD_LIBRARY_PATH; HCISITEDIR=’/qdxiprod/cis6.1/integrator/physician1′; export HCISITEDIR; MANPATH=’/qdxiprod/cis6.1/integrator/man:/qdxiprod/cis6.1/integrator/tcl/man:/qdxiprod/cis6.1/integrator/dbms/man::’; export MANPATH; DBDPATH=’/qdxiprod/cis6.1/integrator/physician1/exec/databases’; export DBDPATH; HCISITE=’physician1′; export HCISITE; HCILICFILE=’/qdxiprod/cis6.1/integrator/vers/license.dat’; export HCILICFILE; QUOVADX_INSTALL_DIR=’/qdxiprod/cis6.1′; export QUOVADX_INSTALL_DIR; TCL_LIBRARY=’/qdxiprod/cis6.1/integrator/tcl/lib/tcl8.5′; export TCL_LIBRARY; HCIVERSION=’6.1′; export HCIVERSION; unset HCIMASTERSITEDIR; DBFPATH=’/qdxiprod/cis6.1/integrator/physician1/exec/databases’; export DBFPATH; DEV_NULL=’/dev/null’; export DEV_NULL; ODBCINI=’/qdxiprod/cis6.1/integrator/lib/Connect7.1.2/odbc.ini’; export ODBCINI; DBTMP=’/qdxiprod/cis6.1/integrator/physician1/exec/databases’; export DBTMP; LOCKMGR=’lm_cis6.1_physician1′; export LOCKMGR; PATH=’/qdxiprod/cis6.1/integrator/physician1/bin:/qdxiprod/cis6.1/integrator/physician1/scripts:/qdxiprod/cis6.1/integrator/bin:/qdxiprod/cis6.1/integrator/contrib:/qdxiprod/cis6.1/integrator/sbin:/qdxiprod/cis6.1/integrator/dbms/bin:/qdxiprod/cis6.1/integrator/tcl/bin:/qdxiprod/cis6.1/integrator/clgui/bin:/qdxiprod/cis6.1/integrator/clgui/java/bin:/qdxiprod/cis6.1/integrator/usercmds:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/hci/bin:/usr/bin/X11:/sbin:.:/usr/local/bin:/usr/local/scripts:/bin:/home/hci/bin’; export PATH; CLASSPATH=’/qdxiprod/cis6.1/integrator/physician1/java_uccs:.:/qdxiprod/cis6.1/integrator/clgui/lib/cljava.jar:/qdxiprod/cis6.1/integrator/java_uccs:/qdxiprod/cis6.1/integrator/lib/java/DBLookup.jar:’; export CLASSPATH; TK_LIBRARY=’/qdxiprod/cis6.1/integrator/tcl/lib/tk8.5′; export TK_LIBRARY; TCLX_LIBRARY=’/qdxiprod/cis6.1/integrator/tcl/lib/tclx8.4′; export TCLX_LIBRARY; DBTAF=’/qdxiprod/cis6.1/integrator/physician1/exec/databases/rdm.taf’; export DBTAF; HCI root is /qdxiprod/cis6.1/integrator No HCI site

      The key is at the end

      Code:

      HCI root is /qdxiprod/cis6.1/integrator No HCI site

      Can anyone educate me, I know it must be simpler than all this.

    Viewing 9 reply threads
    • Author
      Replies
      • #82149
        Keith McLeod
        Participant

          Here is what I use on RH.

        • #82150
          Terry Kellum
          Participant

            What I have is that the first argument to cron (after the times) is the user context of the program to be run:

            30 05 * * * hci /usr/local/bin/CycleSomeThreads.sh >> /var/log/cyclethreads.log

          • #82151
            Todd Horst
            Participant

              Terry:

              Im guessing you are in the root cron, which is why you need to specify the user.

              That certainly is cleaner but im not sure if i can swing that with my server group.

            • #82152
              Steve Carter
              Participant

                Not sure if this is the same on Redhat, but on AIX I source hci’s profile for each cronjob.

                0 1 * * * (. /home/hci/.profile ; scriptToRun.tcl) >/dev/null 2>&1

                Hope this helps.

                Steve

              • #82153
                Todd Horst
                Participant

                  Thanks guys!

                  Here is what I ended up with.

                  Code:

                  #Define a variable with the command to execute to gain context
                  HCIBASE=/qdxiprod/cis6.1
                  NEWUP=’export CL_INSTALL_DIR=$HCIBASE;eval `$HCIBASE/integrator/sbin/hcisetenv -root ksh $HCIBASE/integrator`’

                  * * * * * eval $NEWUP;showroot

                  By leaving off the site, it simply picks up the default site, which is fine for me, and is better in case sites change over time.

                  You could add `SHELL=/bin/ksh` at the top so that you dont need to prefix with ksh, but i found this wasnt needed.

                • #82154
                  Todd Horst
                  Participant

                    slight tweak, i thought it was working, but it wasnt. This however is.

                    Code:

                    #Define the variable with the command to execute to gain context
                    HCIBASE=/qdxiprod/cis6.1
                    NEWUP=’export CL_INSTALL_DIR=$HCIBASE;source /home/hci/.profile;’

                    #Start of cron commands
                    # . COMMAND – this will run command in the current context. If you exclude this you
                    #             will start a new shell with no context. If you use ‘exit’ while IN context it will stop the rest of the cron line from executing.

                    #This works
                    #* * * * * eval $NEWUP; showroot; setsite physician1; showroot;. $HCIROOT/usercmds/setTest; showroot;
                    0,15,30,45 * * * * eval $NEWUP;. $HCIROOT/usercmds/intmon.sh 2>&1;

                  • #82155
                    Robert Kersemakers
                    Participant

                      Hi all,

                      We are on redhat as well and have some cronjobs running under user hci. We had some problems as well and solved it like this.

                      Here an example of one of our cronjobs:

                      Code:

                      55 23 * * * /home/hci/sethcienv daily_housekeeping_cloverleaf > /dev/null

                      The script ‘sethcienv’ checks whether cloverleaf is running on that node/server and if so sets the environment:

                      Code:

                      if [[ -d /prod/cloverleaf/sites60 ]]
                      then
                        . /etc/profile
                        . /home/hci/.profile
                       # script uitvoeren
                       echo “+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++”
                       $*
                      fi
                      exit 0

                      Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

                    • #82156
                      Todd Horst
                      Participant

                        Nice. I like how you’re including /etc/.profile instead of exporting cl_install_dir. Here is my new newup variable:

                        Code:

                        NEWUP=’. /etc/profile;. /home/hci/.profile’

                      • #82157
                        Robert Kersemakers
                        Participant

                          Glad you got something out of it. And I can’t take the credits for it: I have 2 colleagues who had some fun figuring this out.

                          Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

                        • #82158
                          Russ Ross
                          Participant

                            I source my .profile to set my cron environment, too.

                            In fact, I created a .profile.cron because some stuff can be problematic when the assumption is the login session is interactive.

                            If you have stuff in your .profile that assumes an interactive display like an xterm then here is one technique I have used to help with that.

                            In this section from my .profile.local.end file shows how I only set the title on my xterm if running interactive:

                            Code:

                                 #————————————————-
                                 # make sure running interactive and DISPLAY is set
                                 # before trying to set xterm title on active node
                                 #————————————————-

                                 tty -s
                                 exit_status=$?
                                 # exit_status = 0 for interactive and 1 for non-interactive

                                 if [ “$exit_status” == “0” ] && [ “$DISPLAY” != “” ]; then

                                    # make sure the xterm title and icon is updated with the current information
                                    #
                                    # examples of how to do this
                                    #
                                    #     perl -e ‘print “c[];@ARGVa”‘   “what you want to show on xterm title bar”
                                    # or
                                    #     print -n “33]0;what you want to show on xterm title bar and icon07”

                                    AorB=`hostname | sed ‘s/.*(.)$/1/’`
                                    if [[ “$AorB” = “a” ]]; then
                                       print -n “33]0;TEST Cloverleaf 6.0 ( $SITE ) HA active/primary node-$AorB running on `show_physical_box.ksh`07”
                                    else
                                       print -n “33]0;TEST Cloverleaf 6.0 ( $SITE ) HA active/seconday node-$AorB running on `show_physical_box.ksh`07”
                                    fi
                                 fi

                            Here is the contenst of show_physical_box.ksh in case anyone is curious:

                            Code:

                            #!/usr/bin/ksh

                            # Begin Module Header ==============================================================================
                            #
                            #——
                            # Name:
                            #——
                            #
                            # show_physical_box.ksh
                            #
                            #———
                            # Purpose:
                            #———
                            #
                            # Echo to standard out the physical box name you are currently running on
                            #
                            #———
                            # History:
                            #———
                            #
                            # 2012.12.14 Russ Ross
                            #          – wrote intial version
                            #
                            # 2014.01.03 Russ Ross
                            #          – added entries for DR boxes and calification if a box is unlicensed
                            #
                            # End of Module Header =============================================================================

                            physical_box=”UNKNOWN”
                            machine_ID=`uname -a | awk ‘{print $NF}’`

                            #—————————————
                            # CPB-5A (P740_dcpiplpar5a_00F666384C00)
                            #—————————————

                            if [[ $machine_ID == “00F666384C00″ ]] ; then physical_box=”CPB-P740-5A” ; fi

                            #—————————————
                            # CPB-5B (P740_dcpiplpar5b_00F6665E4C00)
                            #—————————————

                            if [[ $machine_ID == “00F6665E4C00″ ]] ; then physical_box=”CPB-P740-5B” ; fi

                            #—————————————
                            # 1MC-6A (P740_dcpiplpar6a_00F70E284C00)
                            #—————————————

                            if [[ $machine_ID == “00F70E284C00″ ]] ; then physical_box=”1MC-P740-6A” ; fi

                            #—————————————
                            # 1MC-6B (P740_dcpiplpar6b_00F70E274C00) – NOT LICENSED!!!
                            #—————————————

                            if [[ $machine_ID == “00F70E274C00″ ]] ; then physical_box=”1MC-P740-6B (unlicensed)” ; fi

                            #—————————————
                            # DCG-7A (P740_ddpiplpar7a_00F807534C00)
                            #—————————————

                            if [[ $machine_ID == “00F807534C00″ ]] ; then physical_box=”DCG-P740-7A” ; fi

                            #—————————————
                            # DCG-7B (P740_ddpiplpar7b_00F807544C00) – NOT LICENSED!!!
                            #—————————————

                            if [[ $machine_ID == “00F807544C00″ ]] ; then physical_box=”DCG-P740-7B (unlicensed)” ; fi

                            echo $physical_box

                            For some reason was not able to add attachment of sample xterm with title set so here is what shows on the title of the xterm I’m looking at now:

                            TEST Cloverleaf 6.0 (test_russ) HA active/primary node-a running on CPB-P740-5B

                            Russ Ross
                            RussRoss318@gmail.com

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