Search This Blog

Tuesday, March 25, 2008

Read Concurrent Parameters in UNIX shell script

Found this question in one of the forum and thought of creating a blog for same.
Often when concurrent program is created on a shell script there is a need to extract parameters passed from concurrent program in the shell script.
In Shell Script, $1 is the variable that stores following information
- Concurrent Program Short Name
- Request ID
- Login Information(APPS username and password)
- User Id
- User Name
- Printer Name
- Save output Flag
- Print number of Copies
- List of concurrent program parameters

Following code can be used to extract different values


requestid=`(echo $1 | cut -f2 -d' ' | cut -f2 -d= | tr -d '"' )` #request_id
login_usr_pwd=`(echo $1 | cut -f3 -d' ' | cut -f2 -d= | tr -d '"' )` #database username/password
conc_user_id=`(echo $1 | cut -f4 -d' ' | cut -f2 -d= | tr -d '"' | cut -c1-8)` #userid
conc_user_name=`(echo $1 | cut -f5 -d' ' | cut -f2 -d= | tr -d '"' | cut -c1-8)` #username
prog_param1=`(echo $1 | cut -f9 -d' ' | tr -d '"' )` #parameter 1
prog_param2=`(echo $1 | cut -f10 -d' ' | tr -d '"' )` #parameter 2
prog_param3=`(echo $1 | cut -f11 -d' ' | tr -d '"' )` #parameter 3
prog_param4=`(echo $1 | cut -f12 -d' ' | tr -d '"' )` #parameter 4
prog_param5=`(echo $1 | cut -f13 -d' ' | tr -d '"' )` #parameter 5
prog_param6=`(echo $1 | cut -f14 -d' ' | tr -d '"' )` #parameter 6


When connecting to SQLPLUS in shell script, it is always advisable to extract database username and password from parameter($login in our example above) and not hard-code the value in program.

10 Comments:

Anonymous said...

Hi Suresh,

Thx a lot...u code is working perfectly fine.

How to pass the request_id to the procedure which I am calling in the shell script.

Thx N Regs,
Khan.

Anonymous said...

Hi Suresh,

One more thing I want to know....
I have a shell script which is registered as a concurrent program and in shell script I am executing a procedure ( which is not a concurrent program ) and here i want to capture all the messages of a procedure and display in the log file of a shell script.

Appreciate ur help.

Thx,
Khan.

Suresh Vaishya said...

Thanks for your feedback.

For printing messages in the log file from procedure, simply use dbms_output.put_line and that should work fine.

Suresh Vaishya said...

Now that you want to pass request_id and the variable is say request_id, simply pass $request_id in the procedure parameter and that should work fine.

Anonymous said...

But my procedure is not registered as a concurrent program.

Shell script is registered as a concurrent program and in the shell script I am executing a procedure ( once connected to DB ). Now w'll get files LOG & OUT for the shell script b'coz its registered as a concurrent program. Here, I want to display the messages of a procedure in the LOG file of a shell script. Neither DBMS_OUTPUT.PUT_LINE nor fnd_file.put_line(fnd_file.log,'any message') doesnt work in this case. Is there any method where we can capture the messages of a procedure & display in the log file of a shell script.

Appreciate ur help,

Thx N Regs,
Khan.

Suresh Vaishya said...

You can call sqlplus from unix shell script. Within sqlplus you can call the procedure. I will post another topic related to this in weekend. Got to wrap something of more priority.

Anonymous said...

Hi Suresh,
I am having same problem. See below, When I call SqlPlus Script from Shell Script and try to display the messages, Messages are displayed but the problem is in the LOG FILE other things are also displayed and these messages are not displayed in Output file.

Thanks

Suresh Vaishya said...

Did you try using fnd_file.put_line(fnd_file.output,[message])

shimon_bay said...

It has one problem If parameter has spaces for it does not pass the whole string . For example paramater passed has value "SURESH VAISHYA" it passesonly "SURESH"
Do you know work around to pass the whole string

Jack said...

Hi Suresh...I love your site and your knowledge about Oracle.Its amazing how you explain the all things with example.Good job man.
sap partners

Copyright (c) All rights reserved. Presented by Suresh Vaishya