DSSendMail only upon the records reject

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

DSSendMail only upon the records reject

Post by dsedi »

Hi All,

We need to send a mail from the particular JOb if there is any reject records.we have designed like collecting allthe reject records into a sequential file then attaching that file to mail using a after Job subroutine.

The situation is we need to send the mail only if there is any reject records-if there is no rejects then do nothing.

experts- any best approch to accomplish this..

Thanks in advance.
dsuser_cai
Premium Member
Premium Member
Posts: 151
Joined: Fri Feb 13, 2009 4:19 pm

Post by dsuser_cai »

modify the shel script, so that it will send the email only if the reject file has any records. May be you can do a count lines (wc -l) to count the number of lines in the file, and if the number of lines is more than 1 (assuming that the first line is column names) then send email else ignor it.

let me know if you need further help.
Thanks
Karthick
bbobpop1
Participant
Posts: 29
Joined: Sun Jul 20, 2008 9:55 am

Post by bbobpop1 »

Hi,

For the same design, I have developed a routine, which will take the rejected file name and path as arguments.

Then I am checking the record count (wc -l) and if the record count is greater than 1, then I am sending a mail to the user.

Consider, First line in rejected file is column header.

Routine Code:

$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

call DSLogInfo("Routine starting",GetStoreUserStatusValue)
LinkCountUnix = 0
command = "wc -l " :FilePath :FileName
call DSExecute("UNIX",command,LinkCountUnix,ExitStatus)
LinkCountUnix = Field (LinkCountUnix,"/",1,1)
call DSLogInfo("Link Count For " :FileName " is " :LinkCountUnix ,GetStoreUserStatusValue)
If LinkCountUnix = 1
Then
Ans = 0
End
Else
Ans = 1
End

After a job processing, I am calling this routine.

Thanks
Bob
Thanks
bob
dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

Post by dsedi »

dsuser_cai wrote:modify the shel script, so that it will send the email only if the reject file has any records. May be you can do a count lines (wc -l) to count the number of lines in the file, and if the number of lines is more than 1 (assuming that the first line is column names) then send email else ignor it.

let me know if you need further help.
I wrote a script like this

Code: Select all


#!/bin/sh

ATTFILE=$1	# File to be attached and generally requiring encoding
SUBJECT="Error File attachment"	# subject liine
MAILTO=myname@mycompany.com
# Count the number of lines in the file
# The file is sent to wc using cat and a pipe
# because if you say "wc -l $1", you'll get
# the filename in the output also.

numLines=`cat $1 | wc -l`

# Test the number of lines counted
# and issue the desired output

if [ $numLines -gt 1 ]
then

echo "Error File having Data...Sending Email"
uuencode $ATTFILE | mail -s "$SUBJECT" $MAILTO
else
echo "No Data on File"
echo $numLines
cat $1

fi
But I dont see the attachment on output Email .....the process just stops after "Error File having Data...Sending Email" and when i say CTRL C on Unix prompt, it said

Code: Select all

(Interrupt -- one more to kill letter)
Null message body; hope that's ok
and I got a Empty Email with NO attachment.

Please let me know if I am doing something wrong here.

Thanks
Last edited by dsedi on Mon Apr 27, 2009 12:52 pm, edited 1 time in total.
dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

Post by dsedi »

bbobpop1 wrote:Hi,

For the same design, I have developed a routine, which will take the rejected file name and path as arguments.
...
..
Thanks
Bob
Bob Thanks very much.

I assumed that u have created a Transform Functions which will take more then one argument(Not before/after subroutine) ..(coz...you have FilePath and FileName in arguement)

and also

Code: Select all

Then 
Ans = 0 
End
Instead of Ans = 0 we have to use the DSSentmail Routine...is that correct?

Thanks.
bbobpop1
Participant
Posts: 29
Joined: Sun Jul 20, 2008 9:55 am

Post by bbobpop1 »

Hi

I tried to use the "DSSentmail Routine", but I guess I am missing some header file to include. And I am not sure which file to add in the routine.

I was checking each file in a loop and if the return code is "1" then I was sending a mail using notification activity.

Thanks
Bob
Thanks
bob
bbobpop1
Participant
Posts: 29
Joined: Sun Jul 20, 2008 9:55 am

Post by bbobpop1 »

Hi

Can you try / test the same routine without "DSSentmail Routine"?

I was also facing the error with "DSSentmail Routine" in my routine

Thanks
Bob
mikegohl
Premium Member
Premium Member
Posts: 97
Joined: Fri Jun 13, 2003 12:50 pm
Location: Chicago
Contact:

Post by mikegohl »

I normally do this in the sequence job using an exec command utility.

Command
! test -s
Parameter
#$DATA_DIR#/outbound/#USVAR_SETUPPARMS.REJECTFILE#

I use the return value <> 0 to control the link to my Notification Activity.

But if you were going to use a routine, I would use the utilities to get the count from the link that writes to the reject file and not a unix utility.
Michael Gohl
mikegohl
Premium Member
Premium Member
Posts: 97
Joined: Fri Jun 13, 2003 12:50 pm
Location: Chicago
Contact:

Post by mikegohl »

Here is an example of getting the row count without calling a UNIX command:

ACCTREJcount = DSGetLinkInfo( JobHandle, "LKP_Acct", "LINKAcctRejects", DSJ.LINKROWCOUNT )
Michael Gohl
dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

Post by dsedi »

mikegohl wrote:I normally do this in the sequence job using an exec command utility.

Command
! test -s
Parameter
#$DATA_DIR#/outbound/#USVAR_SETUPPARMS.REJECTFILE#

I use the return value <> 0 to control the link to my Notification Activity.

But if you were going to use a routine, I would use the utilities to get the count from the link that writes to the reject file and not a unix utility.
Hi Mike & All,

My design is like this. I have a job performing the lookup and writing the records into a sequential file through the lookup reject link.
I want to sent out an Email only If there is any records exist in the sequential file.

Until now,
I have tried writing a UNIX script to check the line count of the file and call the UNIX mailx functionality

i created a transform function as directed by Bob and used that in a routine activity

NOW, to try your approach, I should have a sequence job. Which contains a job activity (for the job) and then exec command activity.
But what should I have in

#$DATA_DIR#/outbound/#USVAR_SETUPPARMS.REJECTFILE#

I assume DATA_DIR is the parameter for Sequential file which is having reject records...
I am sorry I am not able to get #USVAR_SETUPPARMS.REJECTFILE#

Is this the complete PATH for the Sequential file?


Could you elaborate little more on this for the above said design?

Thanks very much.
mikegohl
Premium Member
Premium Member
Posts: 97
Joined: Fri Jun 13, 2003 12:50 pm
Location: Chicago
Contact:

Post by mikegohl »

Sorry for the confusion. The parameter is just the path/filename. I'm using a combination of ENV Variables and User Variable Activity to set the path and name.
Michael Gohl
mikegohl
Premium Member
Premium Member
Posts: 97
Joined: Fri Jun 13, 2003 12:50 pm
Location: Chicago
Contact:

Post by mikegohl »

I want a return code of zero when there are no rejects, that is why I use the ! operator. I turn off the "Automatically handle job runs that fail" and control the graceful exit of the program myself.
Michael Gohl
mikegohl
Premium Member
Premium Member
Posts: 97
Joined: Fri Jun 13, 2003 12:50 pm
Location: Chicago
Contact:

Post by mikegohl »

mikegohl wrote:I want a return code of zero when there are no rejects, that is why I use the ! operator. I turn off the "Automatically handle job runs that fail" and control the graceful exit of the program myself.
If you don't want to deal with the non zero return code, then use the wc -l command in the execute command activity. It will have a return code of 0 for both empty file and file containing records. You would then need a custom (conditional) expression something like this Field(trim( Execute_Command_5.$CommandOutput) ,' ',1) .
Michael Gohl
dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

Post by dsedi »

mikegohl wrote:..... I turn off the "Automatically handle job runs that fail" and control the graceful exit of the program myself.
There you go... :) That is the Point..I got it...Thanks Mike....Now...It goes well for both the situation.(Data/No data)

Just getting a warning below if there is any data... (I am using ! and <> for control the notification)

Code: Select all

send_mail1..JobControl (@Execute_Command_4): Command ! test -s did not finish OK, reply = '1'
Any advice for this? Thanks in advance.
Last edited by dsedi on Tue Apr 28, 2009 3:52 pm, edited 1 time in total.
dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

Post by dsedi »

mikegohl wrote:Here is an example of getting the row count without calling a UNIX command:

ACCTREJcount = DSGetLinkInfo( JobHandle, "LKP_Acct", "LINKAcctRejects", DSJ.LINKROWCOUNT )
Mike,

We are trying to test the scenario with your above suggestion.In the Job sequence, inside the Job activity trigger I have this below code in Custom(Conditional) Expression

Code: Select all

DSGetLinkInfo( Job_Activity_10.$JobName, "Lookup_70", "DsLink93", DSJ.LINKROWCOUNT )
Now, Its not controlling the Notification as we have expected.

From the DSGetLinkInfo help, i Read
Provides a method of obtaining information about a link on an active stage, which can be used generally as well as for job control. This routine may reference either a controlled job or the current job, depending on the value of JobHandle.
Question: :?:

Can I use the DSGetLinkInfo in the Job activity Trigger expression? Or it should be used something like form "Jobbcontrol" ?

Thanks again for your inputs. It was really helpful.
Post Reply