hcidbinit command running in CRON job

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf hcidbinit command running in CRON job

  • Creator
    Topic
  • #49189
    Rob Lindsey
    Participant

      I have been asked to figure out a way to get some of our maintenance programs to run via CRON.  The ones that I am having issues with have  hcidbinit -ACf  in them.  The error that I get when I try and get the KSH script to run in the background is:

      04/05/2007 12:18:16 [dbi :dbi :ERR /0:training_ib_cmd] Unable to find IDENT database record

      04/05/2007 12:18:16 [cmd :cmd :ERR /0:training_ib_cmd] Initialization of DBI failed

      04/05/2007 12:18:16 [prod:prod:ERR /0:training_ib_cmd] Unable to initialize the Command Thread.

      Of course when I run it from the command line everything works just fine.  This is what my script looks like:

      #!/usr/bin/ksh

      /home/hci/.profile

      user=$(whoami)

      echo “user == $user”

      if [ $user != “hci” ]

       then

         echo “You must be user hci to run this script.”

         exit

      fi

      typeset -i recnum

      typeset -i errnum

      typeset -i err

      err=0

      site=training

      if -z $site

       then

             echo “”

             echo ”   ** Need to supply a site.  Can not run without a site”

             echo “”

             exit

      fi

      autoload setroot

      setroot /qdx/qdx5.3/integrator $site

      recnum=$(hcidbdump -r | wc -l)

      if $recnum -gt 8

       then

             echo “”

             echo ”   ** There is information in the recovery database. Will not run”

             echo “”

             exit

      fi

      errnum=$(hcidbdump -e | wc -l)

      if $errnum -gt 8

       then

             echo “”

             echo ”   ** There is information in the error database. Will not run.”

             echo “”

             exit

      fi

      for proc in `hciprocstatus|sed 1,2d|cut -d” ” -f1`

       do

             echo “Shutting Down Process – $proc”

             hcienginestop -p $proc

             sleep 5

       done

      err=0

      recnum=$(hcidbdump -r | wc -l)

      if $recnum -gt 8

       then

             echo “”

             echo ”   ** There is information in the recovery database. Will not run”

             echo “”

             err=1

      fi

      errnum=$(hcidbdump -e | wc -l)

      if $errnum -gt 8

       then

             echo “”

             echo ”   ** There is information in the error database. Will not run.”

             echo “”

             err=1

      fi

      echo “err == $err”

      if $err -gt 0

       then

             echo “”

             echo “There were errors encountered will start what has been stopped”

             echo “”

             for proc in `hciprocstatus|sed 1,2d|cut -d” ” -f1`

               do

                     echo “”

                     echo “Starting Process – $proc”

                     hcienginerun -p $proc

                     sleep 30

             done

             echo “”

             echo “Done….. ***** There were ERRORS ******”

             exit

      fi

      echo “”

      echo “Stopping Deamons”

      hcisitectl -Kf

      sleep 10

      echo “”

      echo “Initing the databases”

      hcidbinit -A -C -f

      sleep 10

      echo “”

      echo “Starting the Deamons”

      hcisitectl -S

      sleep 10

      echo “”

      for proc in `hciprocstatus|sed 1,2d|cut -d” ” -f1`

       do

             echo “Starting Process – $proc”

             hcienginerun -p $proc

             sleep 30

       done

      echo “Done.”

      exit

      Has anyone gotten the hcidbinit command to work from a background job?

      Thanks in advance.

      Rob

    Viewing 6 reply threads
    • Author
      Replies
      • #61041
        Russ Ross
        Participant

          Cron does not have any environment so that is the first possible issue.

          I see you are running

          /home/hci/.profile

          In your script which might take care of that issues or not depending on what is in /home/hci/.profile

          Also cron can get hung up with things that prompt to the screen.

          If you look at the mail for the hci user often problems with cron will show up there.

          I have a /home/hci/.profile.cron to handle running scripts from within cron and making sure the environment is correct for cron.

          I would reccommend setting the environments this way instead of within the script so that the appropriate environment is set for each situation ( 1 – inteactive hci user; 2 – cron).

          Also if there is terminal output that might not be benificial in cron be sure to >/dev/null to get rid of undesired output.

          Also, a handy way to test if a cron job might work okay is to use

          at now

          /home/hci/.profile.cron; script_to_test.ksh

          then to check for any output or errors

          mail

          Russ Ross
          RussRoss318@gmail.com

        • #61042

          Could you paste your .profile.cron file here, please?

          -- Max Drown (Infor)

        • #61043
          Russ Ross
          Participant

            Here is my .profile.cron you requested I post:

            Code:

            # Begin Module Header =========================================================
            #
            # This file is intended to be sourced from within an hci cron entry
            # for the prupose of setting up the environment correctly
            #
            # The cron environment is not the same as the hci environment
            # because the $HOME/.profile does not get run for cron jobs
            #
            #========
            # Inputs:
            #========
            #
               hci_root=$1
               hci_site=$2
            #
            #==============
            # Normal Usage:
            #==============
            #
            #   Example of how to use this from cron to run batch_003 very night at 9:00 PM Monday thru Friday
            #
            #   00 21 * * 1-5 /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_batch; $HCISITEDIR/scripts/_003/iftp_003_cron_entry.ksh’
            #
            #   Example of how to echo the environemnt variables to files /hcitest/env.cron and /hcitest/path.cron at 11:47 AM
            #
            #   47 11 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_batch; env|sort >/hcitest/env.cron; parse_path >/hcitest/path.cron’
            #
            #
            #=========
            # History:
            #=========
            #
            # 2002.05.08 Russ Ross
            #          – wrote initial version.
            #
            # 2005.04.12 Russ Ross
            #          – modified for the QDX 5.2.2 upgrade.
            #
            # End Module Header ============================================================

            #———————
            # define the functions
            #———————

               . /quovadx/qdx5.2/integrator/mda_global/scripts/do_function.ksh

            #————————————
            # define the default HCI profile PATH
            #————————————

               set_HCI_PROFILE_PATH

            #———————————————
            # Make sure our root and site are set
            #———————————————

               setroot -clear
               setroot $hci_root $hci_site

            #———————————————
            # define other necessary environment variables
            #———————————————

               set_IGNORE_VMFULL
               set_MDA_ARCHIVE_ROOT
               set_MDA_BATCH_ENV
               set_MDA_HCIROOT_OFF_LIST
               set_MDA_UPDIR

            Here is the do_function.ksh script that .profile.cron calls:

            Quote:

            #!/usr/bin/ksh

            function set_IGNORE_VMFULL {

               export IGNORE_VMFULL=1

            }

            function set_HCI_PROFILE_PATH {

               PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.:/usr/local/bin:/usr/local/scripts

               export PATH

            }

            function set_MDA_ARCHIVE_ROOT {

                 export MDA_ARCHIVE_ROOT=”/oldmsgs/5.2.1P2″

            }

            function set_MDA_BATCH_ENV {

               MDA_BATCH_ENV=”`echo $HCISITE | cut -b 1-10`”

               if “$MDA_BATCH_ENV” != “test_batch” && “$MDA_BATCH_ENV” != “prod_batch”; then

                   MDA_BATCH_ENV=”bogus_batch”

               fi

               export MDA_BATCH_ENV=$MDA_BATCH_ENV

            }

            function set_MDA_HCIROOT_OFF_LIST {

               if `hostname` = “mdahub1”; then

                   export MDA_HCIROOT_OFF_LIST=”root3.5.2P root3.5.4P root3.5.5C  root3.5.5C_hidden root3.5.5P root3.5.5P_hidden root3.8.1P root3.8.1P_hidden”

               fi

               if `hostname` = “mdahub4”; then

                   export MDA_HCIROOT_OFF_LIST=”root3.5.5C root3.5.5C_hidden root3.5.5P root3.5.5P_hidden root3.8.1P root3.8.1P_hidden”

               fi

            }

            function set_MDA_UPDIR {

               if `hostname` = “mdahub1”; then

                   export MDA_UPDIR=”/upgrade”

               fi

               if `hostname` = “mdahub4”; then

                   export MDA_UPDIR=”/upgrade”

               fi

            }

            function gohome {

               cd `grep “^$1:” /etc/passwd | awk -F: ‘{print $6}’`

            }

            function goprocs {

               cd $HCISITEDIR/exec/processes/$1

            }

            function psgrep {

               echo “”

               ps -ef | head -1

               ps -ef | grep $1 | grep -v grep

               echo “”

            }

            function set522 {

               setroot -clear

               setroot /quovadx/qdx5.2/integrator $1

               showroot

            }

            Here are some sample cron entires to document the cron environment each day in case I need to debug something:

            Code:

            #
            #
            #   ****************************************************************************
            #   document the cron environment **********************************************
            #   ****************************************************************************
            #
            #      ———————-
            #      every day near 5:00 AM
            #      ———————-
            #
            01 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_cbord      ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            02 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_doc_mgt    ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            03 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_emr        ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            04 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_flat_adt   ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            05 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_genie      ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            06 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_global_adt ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            07 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_hdx        ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            08 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_lis        ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            09 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_mymda      ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            10 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_pharm      ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            #???   11 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_pulm_lab   ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            12 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_ris        ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            13 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_sms_21_adt ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            14 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_sms_22_adt ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            15 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_sms_23_adt ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            16 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_sms_order  ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            17 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_sms_sched  ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’
            18 05 * * * /bin/ksh -c ‘eval . ~/.profile.cron /quovadx/qdx5.2/integrator prod_super_adt  ; env|sort >$HCISITEDIR/cron.env; parse_path >$HCISITEDIR/cron.path; functions >$HCISITEDIR/cron.functions’

            Russ Ross
            RussRoss318@gmail.com

          • #61044

            Thanks, Russ.

            -- Max Drown (Infor)

          • #61045
            Gary Atkinson
            Participant

              I am curious with this line of code:

              Code:

              for proc in `hciprocstatus|sed 1,2d|cut -d” ” -f1`

              How could this be change, so that the script goes back and checks to see if all the process are dead?[/code]

            • #61046
              Russ Ross
              Participant

                Gary give this a try and see if it does what you are looking for

                Code:

                hciprocstatus | sed 1,2d | awk ‘{print $2}’

                The problem with using

                Code:

                hciprocstatus|sed 1,2d|cut -d” ” -f1

                when trying to get the second field (f2) is that every space is a field separator when using the cut command.

                So referencing -f2 with the cut command will not have the desired outcome.

                In fact, f2 will almost always be null using the cut command on hciprocstatus output.

                Consequently, the desired field will have a different field number assuming the process names are not all the same length which you would not want to depend on anyway.

                Good Luck.

                Russ Ross
                RussRoss318@gmail.com

              • #61047
                Gary Atkinson
                Participant

                  Ahh that works wonderfully…another unix command to add to my toobox.  Next step would be add in aother loop to check to make sture all processes have really stopped.  Not sure if this is really necessary, but better safe than sorry   😀

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