Page 1 of 1

Read Falt file and email if row>1

Posted: Fri Jul 15, 2005 2:17 pm
by vinaymanchinila
Hi,
I have a reject file in a job, which I need to read at the end of the job or after the job completes and if it has records ,email the same file. I have used unix scripts before but is there a easy way to do it in DS.

Thanks a bunch

Posted: Fri Jul 15, 2005 2:27 pm
by DeepakCorning
See whether you can use the routine DSSendMail.

code = DSSendMail("From:me@here\nTo:you@there\nSubject:Hi ya\nAttach:/usr/AFile.txt\nBody:Line1\n%report%")


"From" Mail address of sender
"To" Mail address of recipient
"Subject" Something to put in the subject line of the message
"Server" Name of host through which the mail should be sent.
"Attach" Path of a file to be sent as a mail attachment - multiple paths may be given, separated by commas.
"Body" Something to put in the body of the message.

Posted: Fri Jul 15, 2005 2:31 pm
by vinaymanchinila
Hi,
Thanks a lot , where does this check if the file has any rows?

Posted: Fri Jul 15, 2005 2:45 pm
by vinaymanchinila
Also I need the content of the file, as I need to send the file content to the end user and the job status is not required.
ANy help!

Posted: Fri Jul 15, 2005 3:00 pm
by pnchowdary
Hi Vinay,

You need to create a job sequencer and follow the below steps to achieve your requirement.

1) Have an ExecuteCommand stage in the sequencer after your job runs and creates the reject file.

2) Call a shell script in the unix, in which you can use

Code: Select all

wc -l <filename>
to the get the no of line in the file. Parse the output of this command and get the actual no of lines.

3) In the triggers tab of the ExecuteCommand stage, make expression type as custom and in the expression, put a condition like

Code: Select all

Execute_Command_0.$CommandOutput > 1
3) Next have a NotificationActivity stage and link the output of the ExecuteCommand stage to this and fill the details in this stage and attach your reject file and send an email to the appropriate person.


Thanks,
Naveen

Posted: Fri Jul 15, 2005 3:09 pm
by vinaymanchinila
Hi Naven,
This sounds great, now should I just give "wc -l Filename.txt" in the window provided?

Also do I need to give the file path, actually we let the files be built in the defulat unix director, like etl/ascential/datastage/files.

Thanks,

Posted: Fri Jul 15, 2005 3:22 pm
by pnchowdary
Hi vinay,

Yes, you need to give the full file path in the below command like

Code: Select all

wc -l /etl/ascential/datastage/file1.txt
The output from the above command will be something like this

Code: Select all

19 /etl/ascential/datastage/file1.txt
You need to extract the numerical part of the output string, which will give you the number of lines and then use this value for further steps.

Thanks,
Naveen

Posted: Fri Jul 15, 2005 3:42 pm
by vinaymanchinila
Hi Navin,
Desgined this job seq, now in the custom condition , I am giving

Execute_Command_1.$CommandOutput[1,1]>1

Then go to the next stage which is a notification stage and has the file
attachment, it doesnt work for some reason.

Posted: Fri Jul 15, 2005 4:08 pm
by vinaymanchinila
Hey Navin,
Thanks for the idea, it worked now. I have used in the Custom condition :

Oconv(Execute_Command_1.$CommandOutput, "MCN") >0

Which takes the numerics out which would be my row count and it works fine!

Posted: Fri Jul 15, 2005 4:08 pm
by pnchowdary
What is the exact error you are getting ?

Posted: Fri Jul 15, 2005 4:11 pm
by vinaymanchinila
It works now !

Posted: Fri Jul 15, 2005 4:23 pm
by pnchowdary
cool :)

Posted: Sat Jul 16, 2005 4:11 pm
by Sainath.Srinivasan
I will suggest you do a different command to extract the row count alone as you may have situation where the file name contains numeric values.