Read a Parameter file from UNIX Directory & pass value

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

DSFreddie
Participant
Posts: 130
Joined: Wed Nov 25, 2009 2:16 pm

Read a Parameter file from UNIX Directory & pass value

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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?
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSFreddie
Participant
Posts: 130
Joined: Wed Nov 25, 2009 2:16 pm

Passing parameter values to Sequence

Post 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.
mosheh
Participant
Posts: 9
Joined: Sat Jul 05, 2008 9:16 am
Location: Sandbox

Post 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.
Moshe H.
DSFreddie
Participant
Posts: 130
Joined: Wed Nov 25, 2009 2:16 pm

Post by DSFreddie »

Thanks Mosheh,

But this is a parallel job.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

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

"You can never have too many knives" -- Logan Nine Fingers
DSFreddie
Participant
Posts: 130
Joined: Wed Nov 25, 2009 2:16 pm

Post 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.
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post 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
You are the creator of your destiny - Swami Vivekananda
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post 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
You are the creator of your destiny - Swami Vivekananda
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSFreddie
Participant
Posts: 130
Joined: Wed Nov 25, 2009 2:16 pm

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

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

"You can never have too many knives" -- Logan Nine Fingers
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post 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.
Mamu Kim
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

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

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