Conditional execution of job

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

suja.somu
Participant
Posts: 79
Joined: Thu Feb 07, 2013 10:51 pm

Conditional execution of job

Post by suja.somu »

I have to execute a job based on a file count.
If the file count =0 then execute the job
Else if file count > 0 then send an email and stop the sequence flow.

how to do this in Sequencer?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That could just be trigger expressions. After you count the file (Execute Command stage most likely) then two triggers from it could evaluate the output and branch to either a Job Activity stage or a Notification stage.

What have you tried so far?
-craig

"You can never have too many knives" -- Logan Nine Fingers
suja.somu
Participant
Posts: 79
Joined: Thu Feb 07, 2013 10:51 pm

Post by suja.somu »

I started with the execution command activity to count the no.of lines in a file in windows command.

I am new to windows scripting. There is a file with rejects data, I have to get the total no.of rejects in afile.

I am using the below command in the execute command activity.

findstr /R /N "^" D:\APP_DATA\VBS\PAS\CIA\REJECTS\SOURCE\ALISSourceRejects.csv | find /D ":"

am getting the below error:

test_seq..JobControl (@Execute_Command_0): Executed: findstr /R /N "^" D:\APP_DATA\VBS\PAS\CIA\REJECTS\SOURCE\ALISSourceRejects.csv | find /D ":"
Reply=1
Output from command ====>
find: unable to access "/D": The system cannot find the file specified.
find: unable to access ":": The system cannot find the file specified.


How to pass the count in a variable ?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Do you have the MKSToolkit installed on your server? You should nowadays. If so you can use UNIX commands which are a wee bit easier on the eyes:

wc -l D:\APP_DATA\VBS\PAS\CIA\REJECTS\SOURCE\ALISSourceRejects.csv
-craig

"You can never have too many knives" -- Logan Nine Fingers
suja.somu
Participant
Posts: 79
Joined: Thu Feb 07, 2013 10:51 pm

Post by suja.somu »

Thanks Craig for your prompt response.

I need to write the windows script to get the file count.
What is the error in the above command, what am i missing ?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Not sure, my DOS days are way behind me. First thing that jumps out at me though is I don't believe there is a /D option for FIND command, so it assumes it must be a file.
-craig

"You can never have too many knives" -- Logan Nine Fingers
suja.somu
Participant
Posts: 79
Joined: Thu Feb 07, 2013 10:51 pm

Post by suja.somu »

Thanks Craig. You are right.

The actual command is :

findstr /R /N "^" filename.txt | find /C ":"

I used this in cmd prompt and it was giving me the expected result.

When I execute the above command through datastage thro a execute command stage, it was throwing error.

For more information, the datastage is installed in a windows server, we access through citrix.

Not sure , where is the issue. Can anyone help to me fix this.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You'd have to post the error.
-craig

"You can never have too many knives" -- Logan Nine Fingers
suja.somu
Participant
Posts: 79
Joined: Thu Feb 07, 2013 10:51 pm

Post by suja.somu »

In the execution command task i gave the command

findstr /R /N "^" D:\APP_DATA\VBS\PAS\CIA\REJECTS\SOURCE\ALISSourceRejects.csv | find /C ":"

In the log i see the below error:

test_seq..JobControl (@Execute_Command_0): Executed: findstr /R /N "^" D:\APP_DATA\VBS\PAS\CIA\REJECTS\SOURCE\ALISSourceRejects.csv | find /C ":"
Reply=1
Output from command ====>
find: unable to access "/C": The system cannot find the file specified.
find: unable to access ":": The system cannot find the file specified.



what is the error in the above statement.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So the same error again, this time with a "C" rather than a "D". I don't have time right now for more trouble-shooting but I'll ponder this.
-craig

"You can never have too many knives" -- Logan Nine Fingers
suja.somu
Participant
Posts: 79
Joined: Thu Feb 07, 2013 10:51 pm

Post by suja.somu »

can anyone help me in fixing the issue.

I am getting the same error. Searched in couple of forums and could not find any resolution.

Requirement:

Job 1 creates a file . File is in windows server
I have to trigger job 2 only if job1 file count =0
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I think you'd need to open a case with your official support provider if you haven't already. You're right, this old DOS mechanism to count lines in a file works just fine from the command line. This is me executing one on Windows 7:

Code: Select all

D:\>findstr /R /N "^" c:\temp\bootstrap_log.txt | find /C ":"
32
I thought perhaps quotes were getting stripped but your echo of the command in the log shows everything intact. I'm sorry but I have no idea what is making it not work. Only suggestion (which I really don't think will change the behaviour) is to put only the "findstr" part in the Command prompt and everything else in the Parameter section. This since you said it all went in as the Command.
Last edited by chulett on Fri Mar 08, 2013 8:59 am, edited 2 times in total.
-craig

"You can never have too many knives" -- Logan Nine Fingers
prasannakumarkk
Participant
Posts: 117
Joined: Wed Feb 06, 2013 9:24 am
Location: Chennai,TN, India

Post by prasannakumarkk »

one thing we must be clear in this:
is it file count
or the record count in file
Since you said reject file, even when there are no rejects empty file will be created.
In that case just use type/more command or command that display file content.
In the expression, check the length of command output.
Mentioning above solution just in case if you didnt get any
Thanks,
Prasanna
suja.somu
Participant
Posts: 79
Joined: Thu Feb 07, 2013 10:51 pm

Post by suja.somu »

Thanks for your reply.

I need the record count in a file. Yes it creates a empty file when there is no record.

I am not able to understand the solution that you had provided. Can you please elaborate more.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Can you try what I posted in my second post, the UNIX command? That will let us know if you have the MKS Toolkit installed and if it works would greatly simplify things:

Code: Select all

wc -l D:\APP_DATA\VBS\PAS\CIA\REJECTS\SOURCE\ALISSourceRejects.csv
Worth a shot before we burn any more braincells on a DOS solution. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply