Get Output from sqlplus prompt in bash script -


i have issue in writing bash script.

i trying output sqlplus prompt bash variable. tried many ways suggested in many forums.

t=$(./bin/sqlplus 'oracleuser/password@(description=(address=(protocol=tcp)(host=192.168.1.2)(port=1521))(connect_data=(sid=connectstring)))' << end select (1 - (sum(getmisses)/(sum(gets) + sum(getmisses)))) * 100 v\$rowcache;  exit; end )  echo $t 

this trying exactly. in above, generating string

'oracleuser/password@(description=(address=(protocol=tcp)(host=192.168.1.2)(port=1521))(connect_data=(sid=connectstring)))'  

dynamically. part works well, issue comes when passing command

select (1 - (sum(getmisses)/(sum(gets) + sum(getmisses)))) * 100 v\$rowcache; 

in sqlplus prompt. here happens like, $ symbol getting escaped, * symbol causes issues (like in sqlprompt lists files in directory runs!) when running command whole.

i have coded :-

connect="'oracleuser/password@(description=(address=(protocol=tcp)(host=192.168.1.2)(port=1521))(connect_data=(sid=connectstring)))'"  arr[1]="select (1 - (sum(getmisses)/(sum(gets) + sum(getmisses)))) * 100 v\$rowcache;"  exp=$(./bin/sqlplus $mconnect << end printf "${arr[1]}"; exit; end )  echo $exp 

when running script, enters sqlplus, when running select command * causing issues, if entering commands manually works.

is there better way exists ? not bash geek :( .

i need real help!

thanks taking time @ issue.

best regards, bhuvanesh

how running query separate query1.sql file?

also, if want result (in case, of (1 - (sum(getmisses)/(sum(gets) + sum(getmisses)))) * 100) returned , no header info, use sqlplus -s.

sqlplus -h 

-s sets silent mode suppresses display of sql*plus banner, prompts, , echoing of commands.

bash.sh:

#/bin/bash     connect="'oracleuser/password@(description=(address=(protocol=tcp)(host=192.168.1.2)(port=1521))(connect_data=(sid=connectstring)))'"      exp=$(./bin/sqlplus -s $connect << end     @query1.sql     end     )  echo $exp 

query1.sql:

set head off select count(*) all_users; exit 

then run example..

./bash.sh 36 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -