variable not getting asked....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting variable not getting asked....
# 1  
Old 12-14-2010
variable not getting asked....

Hello all, I am trying to pass or trying to get a variable assinged...but seemed like i am doing something wrong here....
so lets say abc.txt(spool the output out) is my file, where i am doing select * Fro mv$version inside my DB and getting some info.
Code:
[db11g]-/home/oracle/logs >cat abc.txt
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

SQL> exit
[db11g]-/home/oracle/logs >
[db11g]-/home/oracle/logs >
[db11g]-/home/oracle/logs >
[db11g]-/home/oracle/logs >cat abc.txt |grep Release|awk '{print $7}'
11.2.0.1.0
[db11g]-/home/oracle/logs >

when i cat abc.txt and grep for relase and pipe that to AWK to get 11.2.0.1.0....i get that...but when i pass that on into a vaiable...it do not work....

so when i pass DB_VERSION is my variable....and i am greppging for Relase and the piping that using AWK for my output....i do not get anything back....when i echo $DB_VERSION....it comes out blank....what am i doing wrong here ???
Code:
DB_VERSION=`sqlplus -s /nolog <<EOF | awk -F= "/^a=/ {print \$2}" |grep Release|awk '{print $7}'
set head off pagesize 0 feedback off linesize 200
whenever sqlerror exit 1
conn / as sysdba
SELECT * FROM V$VERSION;
EOF`

[db11g]-/home/oracle/logs >echo $DB_VERSION

[db11g]-/home/oracle/logs >


Last edited by Scott; 12-14-2010 at 05:02 PM.. Reason: Code tags, please...
# 2  
Old 12-14-2010
Hi.

One of your problems is that the shell is expanding the $VERSION of V$VERSION.

Either escape the $ (V\$VERSION), or stop the shell expanding anything between the "EOFs" by using <<"EOF".

I get this output from the select:
Code:
SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE	10.2.0.3.0	Production
TNS for Linux: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production

That makes your awk a problem too. Nothing starts with "a=", and there is no = in the output, so the -F= serves no purpose.

Code:
DB_VERSION=$(sqlplus -s /nolog <<EOF | awk '/^Oracle Database/ { print $7 }'
conn / as sysdba
set head off pagesize 0 feedback off linesize 200
whenever sqlerror exit 1
conn / as sysdba
SELECT * FROM V\$VERSION;
EOF)


Last edited by Scott; 12-14-2010 at 05:35 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can I trace who asked for reboot

Hi, I have an unexpected reboot happening on a Debian 9.9 server. Yesterday 2019-12-01 at 8:30:34 a reboot happened without me or my team being aware: /var/log/syslog:Dec 1 08:30:34 xxxx shutdown: shutting down for system reboot /var/log/syslog:Dec 1 08:30:34 xxxx init: Switching to... (4 Replies)
Discussion started by: chebarbudo
4 Replies

2. UNIX for Beginners Questions & Answers

Sudo asked for root password .

i have tried to use a sudo command from a user level . but instead of asking for user password it asked for root password . how should i go about it . james@opensuse:/etc> sudo ifconfig root's password: And i wish to ask how should i allow a list of command to be allowed to used for a... (4 Replies)
Discussion started by: lobsang
4 Replies

3. Shell Programming and Scripting

Username password asked during loging

Hi, Whenever I open my unix box,after providing username and password I get the following message. Are you authorised to use this computer as detailed above? (Y)es/(N)o : y Export: Release 10.2.0.2.0 - Production on Mon May 16 16:00:15 2011 Copyright (c) 1982, 2005, Oracle. All rights... (5 Replies)
Discussion started by: emilybose
5 Replies

4. AIX

Career Advice Asked

Dear All i am working on windows plattform and i am interested in Aix so i have done IBM Aix certification, can you please suggest Aix filed is good for my carrier,currently i am working as Desktop admin edit by bakunin: please understand that the question you raised has nothing to do with the... (1 Reply)
Discussion started by: manzur13
1 Replies

5. Programming

put the prog asked in your interview

Submit the program asked to write in the interview eg. write a prog to generate fibonacci series using recursion (2 Replies)
Discussion started by: useless79
2 Replies

6. Shell Programming and Scripting

how to set up ssh, so password not asked

Hi All Plz guide me in setting ssh on local machine so that password will not be asked. I have written a script abc.ksh on machineA to execute a script sampletest.ksh available on machineB Conent of abc.ksh is as follows ssh -q bali@machineB sh ClaimGenFeed/claim/sampletest.ksh... (1 Reply)
Discussion started by: balireddy_77
1 Replies

7. Shell Programming and Scripting

asked question about script before missed ansewr..

linux fedora core2 :) i am trying to write a script to clear, date, pwd and tty a linux termnal or konsole.. when I test the tty against $0 i am, getting a premission denied on the terminal that I am trying to printf to.. I tried using an awk command, test condition, an if then fi clause, but... (6 Replies)
Discussion started by: moxxx68
6 Replies

8. Shell Programming and Scripting

I thought I asked the question before but I haven't sorry

:D could any one answer my previous question... just looked through logg and found no such question that I had asked.. please any input would help \.. :confused: (2 Replies)
Discussion started by: moxxx68
2 Replies

9. UNIX for Dummies Questions & Answers

Simple Question ever asked

How do I cahnge my plan under my profile? (5 Replies)
Discussion started by: D3adRabbit
5 Replies
Login or Register to Ask a Question