9 Replies Latest reply on Nov 16, 2015 9:35 AM by Bill Robinson

    Set Schedule on a batch Job via NSH.

      I need to set schedules on batch jobs using a NSH script. I have several of these I need to run monthly, on a specific date \ time each month. Any thoughts on how to schedule a batch job. I have other pieces in place for deploy jobs where I can pull the schedules from a csv. Hoping that I can do the same here.

       

       

      #!/bin/nsh

      BATCHJOB_DBKEY=`blcli BatchJob getDBKeyByGroupAndName "/marty" "batchjob1"`

      # Set the job schedule

      DATE_STRING="2016-01-01 23:35:00"

      BATCHJOB_KEY=`blcli BatchJob addOneTimeSchedule "$BATCHJOB_DBKEY" "$DATE_STRING"`

       

      this fails with:

       

      Error 11/13/2015 14:19:51 Unknown command : name space = 'BatchJob', command = 'addOneTimeSchedule'.com.bladelogic.om.infra.cli.factory.CommandNotFoundException: Name space : BatchJob has no commands by name : addOneTimeSchedule

       

       

      thanks for any input.

       

        • 1. Re: Set Schedule on a batch Job via NSH.
          Bill Robinson

          use Job addOneTImeSchedule.

           

          and use the performance commands if you are going to be running a lot of commands in sequence

           

          blcli_execute BatchJob getDBKeyByGroupAndName "/marty" "batchjob1"

          blcli_storeenv BATCH_JOB_KEY

          # Set the job schedule

          DATE_STRING="2016-01-01 23:35:00"

          blcli_execute Job addOneTimeSchedule ${BATCH_JOB_KEY} "${DATE_STRING}"

          blcli_storeenv BATCH_JOB_KEY

          ....

          1 of 1 people found this helpful
          • 2. Re: Set Schedule on a batch Job via NSH.

            Bill,

             

            this is Just what I needed.

             

            thank you

            • 3. Re: Set Schedule on a batch Job via NSH.

              Bill,

               

              if you are interested this is what I am doing with that. I have a PowerShell script that build a csv file and automatically generates the dates I need this to run  based off of separation from the second Tuesday each month.

               

              The  CSV Looks like this.

              BATCH_JOB_NAME,BATCH_JOB_GROUP,COMMIT_DATE,COMMIT_TIME

              batchjobname,/batch/job/path,2016-01-15,22:00:00

               

               

              here is the NSH.

               

              #!/bin/nsh

              HOST=
              INPUT_CSV=

              # Process the command line
              while getopts :h:i: Option
              do
                     case $Option in
                            h) HOST=$OPTARG;;
                            i) INPUT_CSV=$OPTARG;;
                            \?) echo "Incorrect command line option."
                                   exit 1;;
                     esac
              done

              assert ()
              {
                if test $1 -eq 11 ; then
                     return 0
                elif test $1 -ne 0 ; then
                  echo "####### ERROR: $2; RC=$1" >&2
                  exit 1
                fi
              }

              # Check INPUT_CSV exists
              if [ ! -f $INPUT_CSV ];then
                echo "Input CSV [$INPUT_CSV] not found."
                exit 1
              fi

              INPUT_CSV_NUM_LINES=`cat $INPUT_CSV | wc -l`
              LINE_CNT=2

              while [ $LINE_CNT -le $INPUT_CSV_NUM_LINES ]
              do
              input_csv_line=`sed -n "${LINE_CNT}p" $INPUT_CSV`

              BATCHJOB=`echo $input_csv_line | cut -f1 -d,`
              BATCHGROUP=`echo $input_csv_line | cut -f2 -d,`

               

               

              # Get the Batch Job DBKey using the above information. 
              BATCHJOB_DBKEY=`blcli_execute BatchJob getDBKeyByGroupAndName "${BATCHGROUP}" "${BATCHJOB}"`

              # Set the job schedule

              DATE_STRING="2016-01-01 23:35:00"

              BATCHJOB_KEY=`blcli_execute Job addOneTimeSchedule "${BATCHJOB_DBKEY}" "${DATE_STRING}"`


              LINE_CNT=`expr $LINE_CNT + 1`
              done

              • 4. Re: Set Schedule on a batch Job via NSH.
                Bill Robinson

                yeah - you should use the perf commands - your script will run a lot faster.

                 

                also - what's going on w/ all this:

                INPUT_CSV_NUM_LINES=`cat $INPUT_CSV | wc -l`
                LINE_CNT=2

                while [ $LINE_CNT -le $INPUT_CSV_NUM_LINES ]
                do
                input_csv_line=`sed -n "${LINE_CNT}p" $INPUT_CSV`

                BATCHJOB=`echo $input_csv_line | cut -f1 -d,`
                BATCHGROUP=`echo $input_csv_line | cut -f2 -d,`

                 

                ?

                 

                 

                if you want to read all the lines except the header why not either not generate the header row in the csv or do like:

                 

                while IFS=, read BATCHJOB BATCHGROUP COMMIT_DATE COMMIT_TIME

                do

                DATE_STRING="${COMMIT_DATE} ${COMMIT_TIME}"

                blcli_execute BatchJob getDBKeyByGroupAndName "${BATCHGROUP}" "${BATCHJOB}"

                blcli_storeenv BATCH_JOB_KEY

                # Set the job schedule

                blcli_execute Job addOneTimeSchedule ${BATCH_JOB_KEY} "${DATE_STRING}"

                blcli_storeenv BATCH_JOB_KEY

                done <<< "$(grep -v "^BATCH_JOB_NAME" "${INPUT_CSV})"

                • 5. Re: Set Schedule on a batch Job via NSH.

                  I have around 30 batch jobs that I need to set schedules on. I use a powershell script to generate a csv file that has the name and path to the jobs. Then it calculates the cate based on patch Tuesday + xx days. Once the csv file has been created I can run the nsh script to set the schedule on all 30 jobs. Doing it this way takes 2-3 mintues vs and hour or so to set them manaually.

                   

                  I use the same process to set the schedules on all of my windows patch jobs.

                  • 6. Re: Set Schedule on a batch Job via NSH.
                    Bill Robinson

                    ?ok - the 'performance commands' (blcli_execute) will run faster than the normal blcli because a jvm is only started once.  for calling the blcli 30 times you should see an improvement though this job doesn't seem time critical.

                    • 7. Re: Set Schedule on a batch Job via NSH.

                      Bill,

                       

                      Thanks. No these jobs are not time critical. I will normally set the schedules a week or so ahead of time. They need to run once a month. Just trying to avoid the tedious task of setting 30 schedules manually, along with the possibility of getting a date \ time wrong on one.

                       

                       

                      Martin Gomez

                      Lead Systems Administrator

                      816 435-6067

                      816 564-8876 (cell)

                      • 8. Re: Set Schedule on a batch Job via NSH.

                        Bill,

                         

                        Another thing worth noting. When the job runs and the format of the time is not correct. The target job executes NOW, instead of the set schedule just failing. I corrected my PowerShell script to ensure the time was 04:00:00 and it works as expected.

                         

                         

                         

                        • 9. Re: Set Schedule on a batch Job via NSH.
                          Bill Robinson

                          the above blclis are the only ones you are running?  if the set schedule fails i would not expect the job to be executed.