?
Solved

batch file to open sqlplus

Posted on 2011-09-27
2
Medium Priority
?
792 Views
Last Modified: 2012-08-14
Hi,

I have a dozens of batch files that I use to automate SQLPlus (and SQLCMD).  I need to change my db passwords frequently, and updating all of my batch files is a big pain.  

Could I store the pw in a single place and call it from the batch file?

Here's what a current sqlplus batch file looks like:
chdir "O:\Automation"
sqlplus user/passwrd@db @example.sql

what I'd like to have is only one file that contains my password
something like C:\securefolder\password.txt

Can I reference that in the batch file to get the pw?

Thanks!
0
Comment
Question by:TelMaco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Accepted Solution

by:
TelMaco earned 0 total points
ID: 36713741
I found a solution here:
www.computing.net

I took the suggestion from klint and modified it to this:
@echo off
setlocal enabledelayedexpansion
set ConStr=
for /f "delims=" %%a in (mydb_constr.txt) do (
  set currentline=%%a
  set ConStr=!ConStr!!currentline!
)

chdir "O:\Automation"

SET tns_admin=C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN

%ConStr%

cmd

Open in new window


Where the file (mydb_constr.txt) contains the connection string
"sqlplus user/passwrd@db @example.sql"
0
 

Author Comment

by:TelMaco
ID: 36717534
To clarlify in case anyone else finds this helpful...

I figured out how to make this work with just the pw, rather than the whole connection string.

I changed this line:
%ConStr%
to this:
!sqlplus user/%ConStr%@db @example.sql!

and then modified the .txt file to just store the pw

I didn't realize I could combine it all using the "%" symbol and tie it all in with the "!"

Looking back at the question I probably should have called this something like "referencing a variable in batch file" if a mod comes across this maybe you could change the title so others can find this easier?

Thanks EE!



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question