Capturing value into variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capturing value into variable
# 1  
Old 08-19-2003
Question Capturing value into variable

Hi,

I am new to shell scripting, I am trying to write a shell script, which will automate the process of mailing the invoices at the end of the day. For major part I am using Oracle database function.
The problem is I want to capture the value returned by the Oracle function into the script variable. In fact this value will be a command which when exceuted will send the mail.
This is a part of the script:
#---------------
#/usr/lib/sendmail $tomail < $tmpfile
ERR=$?
if [ $ERR = 0 ]; then
sqlplus -s username/password << EOF
DECLARE
l_error varchar2(100);
l_command varchar2(1000);
l_inv number;
BEGIN
my_oracle_package.invoice_proc(NULL,NULL,400,l_inv,l_error,l_command);
END;
/
exit 0
# Here I would like to capture l_command into some variable.
EOF
#-------------
Now I want to capture the value l_command(Character 1000) returned by Oracle procedure. Is this possible, if yes , how?

Thanks
Prasad.
# 2  
Old 08-19-2003
Hi Phrasad,

It is possible to get the exit code of each forked process. It's up to the process to use a valid exit code. For instance SQL could deside to exit with the code 3489, I would not know what to do with this code, but SQL can do this.
So when you start SQL you fork, when this fork returns to it's parent, "the exit from out of sql" you will see the return code from SQL. The fork cannot tell exit codes from inside another programm. Maybe from inside SQL you are able to capture the exit code and use this to exit out of SQL.
Hope this helps.

Regs David
# 3  
Old 08-19-2003
The only way I know of doing this is by extracting your data from your db to a flat file, then setting a variable by using cat and piping to a cut command to extract your result from your sql....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

SED capturing information from a variable

Hi I can't get this line to work. I need to capture what is between Home and plugin_out, where the .* is located. RUN=`echo '${TSP_FILEPATH_PLUGIN_DIR}' | sed -e 's^/results/analysis/output/Home/\(.*\)/plugin_out/g'`; echo ${RUN}; I'm getting the error sed: -e expression #1, char 51:... (1 Reply)
Discussion started by: jdilts
1 Replies

2. Shell Programming and Scripting

[SOLVED] Capturing output in a korn variable

Hi, I'm new to korn and having trouble capturing the text output from one program in an array that I can then feed into another program. Direct approaches didn't work, so I've tried to break it down thus: The program lonlat2pixline gives the values I need in the second column, so I print that... (4 Replies)
Discussion started by: daurin
4 Replies

3. Shell Programming and Scripting

Help with capturing homedir via ssh and saving to variable

I need to capture the homedir using the ssh command and then saving it to a variable. The results from the following command is what I need to capture to a variable: NOTE: the value I'm getting back is also incorrect. as it seems to be getting the home dir from the local server and not the... (2 Replies)
Discussion started by: reneuend
2 Replies

4. Shell Programming and Scripting

capturing a file to store in a variable

I have a file in a windows directory the file is delivery to us like this 07210900.dat where 07210900 is the current date. If I want to store that file in a variable UpLoadFileName and rename, so I can Ftp later to a UNIX directory, I am doing this, is this correct? CDRemoteDir='cd... (0 Replies)
Discussion started by: rechever
0 Replies

5. UNIX for Dummies Questions & Answers

Capturing a value in to variable.

Hi, I currently have a shell script where it captures in the value in to 'TOTAL' and outputs to a file, i want to capture another value of a query in to another variable and output it. Current script: sqlplus -s $user <<EOD | read TOTAL set heading off set pages 0 set feedback off set... (1 Reply)
Discussion started by: ravi0435
1 Replies

6. Shell Programming and Scripting

Losing new lines when capturing output to variable

Explain this? $ ls | grep -e "crd\|cs" crd cs $ CLONES=`ls | grep -e "crd\|cs"`;echo $CLONES; crd cs $ CLONES=`ls | grep -e "crd\|cs"`;echo "$CLONES"; crd cs (1 Reply)
Discussion started by: blasto333
1 Replies

7. Shell Programming and Scripting

capturing the o/p to a variable

Hi, #Script mentioned below txt=($(echo `./demo1.sh`)) p=0 for p in "$txt" do col=($(./generateTable /import/data01/sri/Developer/SqlReport/Lab/23/${var} "$p")) . . . . done o/p displayed upon executing a script called "demo1.sh" is as below(two seperate lines):... (2 Replies)
Discussion started by: villain41
2 Replies

8. Shell Programming and Scripting

Capturing a number at the end of line and store it as variable

Hello, Would someone guide me on how to write a shell script the would search for a phone no using at the end text file using sed or awk and store it in a varaible or print it. The text file is in this form text or numbers in first line text or numbers in second line . . . Firsname... (6 Replies)
Discussion started by: amuthiga
6 Replies

9. UNIX for Dummies Questions & Answers

Capturing some data from a file into a variable

I have a file with some values in a tab delimted format Eg: 'test' contains: a<tab>b<tab>c<tab>Trk_12345678 now i need to capture this value 'Trk_12345678' into a variable say 'x' and append that value of 12345678 to 12345679 and store is back to a new 'test1' file as : 'test1'... (11 Replies)
Discussion started by: shiroh_1982
11 Replies

10. UNIX for Dummies Questions & Answers

capturing the output of grep as integer variable

Hi, I have an expression using grep and nawk that captures the ID number of a given Unix process. It gets printed to screen but I don't know how to declare a variable to this returned value! For example, ps -ef|grep $project | grep -v grep | nawk '{print $2}' This returns my number. How... (2 Replies)
Discussion started by: babariba
2 Replies
Login or Register to Ask a Question