2 Replies Latest reply on Sep 17, 2012 8:19 PM by Bill Robinson

    Job Run Notification - add logs

    Dror Ezion

      Hello,

       

      I am runing NSH script job and I would like to have with the job notification email the log of this script, can someone have idea how to do it ?

       

      thanks,

       

      Dror

        • 1. Re: Job Run Notification - add logs

          Out of box, this is not possible, but here's one idea:

          Create another NSH Script Job (can be run sequentially in Batch Job after your NSH Script Job). This second script job will check for the status of your initial job, and if failed, will export the log and email it to you or copy the log to some designated location.  (do not know how to script the "email with attachment part", but if you consider this option and also do not know how, then I'd google)

          1 of 1 people found this helpful
          • 2. Re: Job Run Notification - add logs
            Bill Robinson

            you could do it w/ this script.  you put in the script you want to run as inputs to this script and run this one as the nsh script job.  it will call the other script, then export the run log and email you.

             

            #!/bin/nsh

            blcli_setoption serviceProfileName defaultProfile
            blcli_setoption roleName BLAdmins
            blcli_connect

            jobType="${1}"
            jobFolder="${2}"
            jobName="${3}"
            notifyType="${4}"
            contact1="${5}"
            contact2="${6}"

            emailFrom="${USER}@`uname -n`"

            blcli_execute ${jobType} getDBKeyByGroupAndName "${jobFolder}" "${jobName}"
            blcli_storeenv jobKey
            blcli_execute ${jobType} executeJobAndWait "${jobKey}"
            blcli_storeenv jobRunKey
            blcli_execute JobRun getStartTimeByRunKey "${jobRunKey}" "yyyyMMddHHmmss"
            blcli_storeenv runTime

            if [ "${jobType}" = "DeployJob" ]
                    then
                    blcli_execute Utility exportDeployResults "${jobKey}" "${jobRunKey}" "/tmp/${jobName}_${runTime}.csv"
            elif [ "${jobType}" = "NSHScriptJob" ]
                    then
                    blcli_execute Utility exportNSHScriptResults "${jobRunKey}" "/tmp/${jobName}_${runTime}.csv"
            else
                    echo "[ERROR] Job type: ${jobType} not supported"
                    exit 1
            fi

            if [ "${notifyType}" = "email" ]
                    then
                    blcli_execute Email sendMailWithAttachment "${emailFrom}" "${contact1}" "${jobName} ${runTime} Detail Log" "${jobName} ${runTime} Detail Log" "/tmp" "${jobName}_${runTime}.csv"
                    rm -f "/tmp/${jobName}_${runTime}.csv"
            elif [ "${notifyType}" = "file" ]
                    then
                    [ ! -d "//${contact1}${contact2}" ] && mkdir -p "//${contact1}${contact2}"
                    mv "/tmp/${jobName}_${runTime}.csv" "//${contact1}${contact2}"
            else
                    echo "[ERROR] Notify Type: ${notifyType} not supported"
                    exit 1
            fi

            1 of 1 people found this helpful