Solved

batch file to open sqlplus

Posted on 2011-09-27
2
780 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

730 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