Batch Job - send email issue

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
shrey3a
Premium Member
Premium Member
Posts: 234
Joined: Sun Nov 21, 2004 10:41 pm

Batch Job - send email issue

Post by shrey3a »

Hi Gurus,

I've created a batch job which run all the jobs in parallel from a category.
I want to send an email if the job is finished with warnings with subject as job name or message as job name.

I'm able to send email for any jobs abort or finished with warnings but the subject is not dynamic i.e. Job Name , below is the code for same.

Thanks in advance for help

I even tried to create a normal batch job by adding all the jobs thru generated code and was able to send email individually but then jobs do not run in parallel I removed the dependency from dependency tab somehow they execute in sequence.

ProjName = DSGetProjectInfo (DSJ.PROJECTNAME)

TrimmedProjName = Field(Trim(ProjName), "_", 1, 2)
FolderName = 'chart'

cmd="SELECT NAME FMT '60R' FROM DS_JOBS WHERE CATEGORY LIKE '%abc\chart' ;"


Call DSExecute("UV",cmd,output,sysretcode)

Call DSLogInfo("Command Is: ":cmd,"Batch Job")

Call DSLogInfo("Output from the command: ":output,"Batch Job")

Final=""

n=DCount(output,@FM)

output=EReplace(output,Char(10),"")

For i=1 To n Step 1

A=Field(output,@FM,i)

JobName=Trim(A)

If IsNull(JobName)=1 OR Count(JobName,"...") > 0 OR Len(JobName) < 1 OR Count(JobName,"records listed.") OR Count(JobName,"\\\abc\chart")
Then

x=1

End Else

If Len(JobName) > 0 Then

* Setup JobName, run it, wait for it to finish, and test for success

hJob1 = DSAttachJob(JobName, DSJ.ERRWARN)
ErrCode = DSRunJob( hJob1, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob1)
Status = DSGetJobInfo( hJob1, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED OR Status = DSJS.RUNWARN
Then
Call DSExecute("UNIX",'/usr/bin/mailx -s JobName "a@yahoo.com"','0','0')
End
End

End
Next i
Call DSLogInfo("Batch Job Completed", "JobControl")
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Please enclose your program in "code" tags to make it legible.

You code issues a call to DSWaitForJob(), this is why it executes in sequence.
shrey3a
Premium Member
Premium Member
Posts: 234
Joined: Sun Nov 21, 2004 10:41 pm

Post by shrey3a »

Our requirement is to run the jobs in particular category and if any job is failed or finished with warning then send an email for that particular job name.


I'm using the below code to check the status of all jobs in a category and even able to send an email but somehow the subject of email is not dynamic i.e. equal to job name.

**************************************
cmd="SELECT NAME FMT '60R' FROM DS_JOBS WHERE CATEGORY LIKE '%Chartfields\Fin_To_EPM\Server' ;"

Call DSExecute("UV",cmd,output,sysretcode)

Call DSLogInfo("Command Is: ":cmd,"Batch Job")

Call DSLogInfo("Output from the command: ":output,"Batch Job")

Final=""

n=DCount(output,@FM)

output=EReplace(output,Char(10),"")

For i=1 To n Step 1

A=Field(output,@FM,i)

JobName=Trim(A)
hJob1 = DSAttachJob(JobName, DSJ.ERRNONE)
Status = DSGetJobInfo( hJob1, DSJ.JOBSTATUS)

If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED OR Status = DSJS.RUNWARN
Then
Call DSExecute("UNIX",'/usr/bin/mailx -s JobName "a@yahoo.com"','0','0')

End

Next i
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

Call DSExecute("UNIX",'/usr/bin/mailx -s ' : JobName : ' "a@yahoo.com"','0','0') 
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply