Page 1 of 2

Read a Parameter file from UNIX Directory & pass value

Posted: Sun Apr 18, 2010 9:12 pm
by DSFreddie
Hi All,

Pls help me in this scenario,

I have a Parameter file in the UNIX directory. I need to read this file, get the values from the file & pass it to the JOB Sequence.

Thanks in Advance,
Freddie.

Posted: Sun Apr 18, 2010 9:18 pm
by chulett
What have you tried? Where do you want to do this - a shell script using dsjob? Some other form of job control code, DataStage BASIC perhaps?

Passing parameter values to Sequence

Posted: Sun Apr 18, 2010 10:53 pm
by DSFreddie
Hi,

Thanks for the reply.

I have a parameter file in the UNIX dir. I am trying to read the file through a Execute COmmand Activity (Through a Script)& pass those values to the subsequent jobs.

Can you pls tell me how to do this & what is the UNIX code I should write. Also, pls let me know how I can pass the output from the UNIX code to the subsequent job.

THanks in advance,
Freddie.

Posted: Sun Apr 18, 2010 11:07 pm
by mosheh
I suggest read the parameter in a server job, in the same job call the SetUserStatus routine with the parameter value. Then pass the User Status to your job in the Sequence.

Posted: Sun Apr 18, 2010 11:37 pm
by DSFreddie
Thanks Mosheh,

But this is a parallel job.

Posted: Sun Apr 18, 2010 11:50 pm
by ray.wurlod
The one that reads one line from a file does not have to be, indeed if it were it would be a waste of resources.

Posted: Mon Apr 19, 2010 6:10 am
by chulett
How are you trying to 'read' this file in that stage? What do the contents of the file actually look like? One or many records? Sometimes a simple 'cat' is all it takes, hence the questions.

Posted: Mon Apr 19, 2010 8:30 am
by DSFreddie
Hi All,

It is a parameter file with a list of values. (More than 6 parameters & corresponding values). I am trying to use an Execute Command activity & capture those values in the next stage.

Pls help.

Also let me know whether there s any other alternative of reading the parameter values from the file & passing it to a sequence.

Thanks
Freddie.

Posted: Mon Apr 19, 2010 9:05 am
by anbu
Use cat command as Chulett said in execute command and use Field command on command output of execute command to retrieve parameter values

Posted: Mon Apr 19, 2010 9:07 am
by anbu
Use cat command as Chulett said in execute command and use Field command on command ouput of execute command to retrieve parameter values

Posted: Mon Apr 19, 2010 9:24 am
by chulett
Best way IMHO is to do this all in hand-coded BASIC job control. Read the file, DSAttachJob(), use DSSetParam() to establish the values and then DSRunJob() to run the Sequence, DSWaitJob(), etc. This is very similar to the job control code you can automatically generate in any job's Properties from the Job Control tab using that drop-down. A little intimidating at first but a great skillset to have that will serve you well, so well worth the time you should invest to learn it.

Otherwise trying to echo out multiple parameter name/value pairs, interrogate what you found and then figuring out what to do with them is a little much to accomplish in a brain-dead Execute Command stage. If you know ahead of time where each one goes, you could echo out the X values in a delimited string and then substring out the appropriate bit X times from the result.

Still prefer the first solution. :wink:

Posted: Mon Apr 19, 2010 2:46 pm
by DSFreddie
Hi All,

My requirement is simple. I have a Parallel Job Sequence. I need to read a parameter file (residing in the UNIX box,, it is a text file)& pass the values in the parameter file to the subsequent job activities.

Pls let me know how I can do it.

Thanks in advance,
Freddie.

Posted: Mon Apr 19, 2010 2:54 pm
by chulett
DSFreddie wrote:Pls let me know how I can do it.
I'm sorry but what in the heck do you think we've been trying to do? Am I just talking to myself here? :?

And while your requirement may be "simple", the solution - when it involves a variable number of parameters in name/value pairs - is not if you've never done it before.

Posted: Mon Apr 19, 2010 5:02 pm
by kduke
You can do this in a sequence but the BASIC code would be in a routine. You still need to parse the parameter file. I assume your parameter file looks like this:

Param.txt

Code: Select all

ParamName=ParamValue
Example:

Code: Select all

jpEdwDsn=OraEdwDev
The tricky part is when you add comments to these.

Example with comments:

Code: Select all

#Prod jpEdwDsn=OraEdwProd
#Test jpEdwDsn=OraEdwTest
jpEdwDsn=OraEdwDev
This allows you to move your parameter file from Dev to Test to Prod and just uncomment the values. Not good for passwords but most of us do something like this.

You can do this in a UNIX command.

Code: Select all

cat Param.txt | grep -v '^#' | grep $1
You need to wrap this in shell script. To do this in BASIC is similar.

Code: Select all

Ans=''
openpath '.' to CurrentDir else stop
read ParamFile From CurrentDir, 'Param.txt else stop
Found=@FALSE
NoLines=dcount(ParamFile, @FM)
For i=1 to NoLines until Found
   Line=ParamFile<i>
   FirstWord = field(Line, '=', 1)
   if FirstWord=ParamName Then
      ParamValue = field(Line, '=', 2, 99)
      Found=@TRUE
   end
Next i
If Found Then
   Ans = ParamValue
End
return(Ans)
(ParamName is the argument to this routine.)

The STOP statements need to have some kind of logic there to trap errors but this is close.

Now in your sequence job set a variable to the result of this routine. Call this over and over until you get all your parameters set. Now you can feed these variables into your job parameters from this point on.

None of this has been tested. So you need to work out the details.

Posted: Mon Apr 19, 2010 5:26 pm
by chulett
As noted, you'd have much more control over things in a nice chunk of BASIC job control code, something that could automatically poll a job for the parameters it needs and then parse them from your flat file or a dynamic array. What Kim posted can be made to work for you if you know the names of the parameters you need and are willing to call this as many times as you need something from the file.

I'd suggest setting these calls up in a UserVariables stage, that way you can easily create the X placeholders you'd need then call them once and just as easily reference them in any number of downstream Job Activity stage's parameter value box.