Solved

batch file to open sqlplus

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
Currency Conversion? 1 87
Base1 Encode/Decode 3 77
What are programming codes and how do they work? 7 95
This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

831 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