Solved

batch file to open sqlplus

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 77
pairs challenge 5 44
Controlled Assessment GCSE - desperate help needed 4 53
Not needed 13 55
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now