Read Falt file and email if row>1

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
vinaymanchinila
Premium Member
Premium Member
Posts: 353
Joined: Wed Apr 06, 2005 8:45 am

Read Falt file and email if row>1

Post 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
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Post 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.
vinaymanchinila
Premium Member
Premium Member
Posts: 353
Joined: Wed Apr 06, 2005 8:45 am

Post by vinaymanchinila »

Hi,
Thanks a lot , where does this check if the file has any rows?
vinaymanchinila
Premium Member
Premium Member
Posts: 353
Joined: Wed Apr 06, 2005 8:45 am

Post 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!
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post 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
vinaymanchinila
Premium Member
Premium Member
Posts: 353
Joined: Wed Apr 06, 2005 8:45 am

Post 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,
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post 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
vinaymanchinila
Premium Member
Premium Member
Posts: 353
Joined: Wed Apr 06, 2005 8:45 am

Post 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.
vinaymanchinila
Premium Member
Premium Member
Posts: 353
Joined: Wed Apr 06, 2005 8:45 am

Post 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!
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post by pnchowdary »

What is the exact error you are getting ?
vinaymanchinila
Premium Member
Premium Member
Posts: 353
Joined: Wed Apr 06, 2005 8:45 am

Post by vinaymanchinila »

It works now !
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post by pnchowdary »

cool :)
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post 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.
Post Reply