We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Shell script: How can I populate a shell script variable with result of sql statement

GlobexCorp
GlobexCorp asked
on
Medium Priority
606 Views
Last Modified: 2013-12-26
I want to populate a shell script variable with the result of a select count(*) sql statement. At the moment I can select the results and write them to a file but now I just want to get the count and populate a shell script varaiable with the value

i.e. I want the variable 'COUNT' to be populated with the result of 'Select count(*) from Table'

I'm a newcomer to shell scripting to so any help would be greatly appreciated

Thanks
Comment
Watch Question

Commented:
COUNT=3 or export count=3, if you want call other scripts which want to use it. If you post your exisiting script we can give more hints.

$ COUNT=3
$ echo $COUNT
3

Open in new window

CERTIFIED EXPERT
Top Expert 2007
Commented:
try

COUNT=`sqlplus user/pass <<END
select count(*) from Table
END`

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks for the reply

I'm not sure of the username/password for the db, I'm working from someone elses code. I'm already accessing the DB so is there anyway of using that code without the inclusion of the user/pass?

Thanks
CERTIFIED EXPERT
Top Expert 2007

Commented:
I am not aware of any other method to access database without username and password

Author

Commented:
At the moment I'm successfully outputting a sql select to a file without using username/password:

'CODE=echo "select max(col) from TestTable where col like 'A%'" | ac_bl -qs -|  ~/developers/bin/runparallel -l20000 -n30","' >> Test_File.csv

I'm not using the user/pass here so I figured it was possible to read from the db the same way and instead of writing to a file populate my variable
CERTIFIED EXPERT
Top Expert 2007

Commented:
I think either ac_bl or ~/developers/bin/runparallel has the username and password
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.