DSSendMail only upon the records reject
Moderators: chulett, rschirm, roy
DSSendMail only upon the records reject
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.
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.
-
- Premium Member
- Posts: 151
- Joined: Fri Feb 13, 2009 4:19 pm
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.
let me know if you need further help.
Thanks
Karthick
Karthick
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
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
bob
I wrote a script like thisdsuser_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.
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
Code: Select all
(Interrupt -- one more to kill letter)
Null message body; hope that's ok
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.
Bob Thanks very much.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
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
Thanks.
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.
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
Hi Mike & All,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.
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.
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) .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.
Michael Gohl
There you go... That is the Point..I got it...Thanks Mike....Now...It goes well for both the situation.(Data/No data)mikegohl wrote:..... I turn off the "Automatically handle job runs that fail" and control the graceful exit of the program myself.
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'
Last edited by dsedi on Tue Apr 28, 2009 3:52 pm, edited 1 time in total.
Mike,mikegohl wrote:Here is an example of getting the row count without calling a UNIX command:
ACCTREJcount = DSGetLinkInfo( JobHandle, "LKP_Acct", "LINKAcctRejects", DSJ.LINKROWCOUNT )
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 )
From the DSGetLinkInfo help, i Read
Question: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.
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.