Page 1 of 2

Conditional execution of job

Posted: Fri Mar 01, 2013 9:15 am
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?

Posted: Fri Mar 01, 2013 9:18 am
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?

Posted: Fri Mar 01, 2013 10:48 am
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 ?

Posted: Fri Mar 01, 2013 11:15 am
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

Posted: Fri Mar 01, 2013 11:44 am
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 ?

Posted: Fri Mar 01, 2013 2:36 pm
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.

Posted: Sat Mar 02, 2013 12:06 am
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.

Posted: Sat Mar 02, 2013 7:57 am
by chulett
You'd have to post the error.

Posted: Sat Mar 02, 2013 10:37 am
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.

Posted: Sat Mar 02, 2013 12:07 pm
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.

Posted: Thu Mar 07, 2013 11:43 pm
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

Posted: Fri Mar 08, 2013 12:13 am
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.

Posted: Fri Mar 08, 2013 12:23 am
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

Posted: Fri Mar 08, 2013 8:55 am
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.

Posted: Fri Mar 08, 2013 9:02 am
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: