You are not logged in.

#1 03 Feb 2015 10:44

platon39
Member
Registered: 24 Feb 2014
Posts: 30

Batch script conect to multiple database

Hello,
i have a script that must connect to multiple database and different passwords kept in the file database.lis



database1  password1
database2  password2

-but i have  problem, the script is connecting to database1 password1, then database1 connect with password2 ,
how can i do to connect database1 with password1
database2 with password2
here is the script:



echo off
cls

::


SETLOCAL EnableDelayedExpansion

for /f   "tokens=1 delims= " %%b in (database.lis) do (

   set database=%%b
   echo.Database !database!
   

ECHO.***********************************************
echo. Connect to !database!
ECHO.***********************************************


for /f  "tokens=2 delims= "  %%c in  (database.lis) do    (   

     set password=%%c
     echo.Password: !password!
     sqlplus system/!password!@!database! @C:\scripturi\verify.sql
pause
  ) 

)

pause
:end
echo.
echo.DONE
echo.Press any key to exit.
pause >nul



Thanks in advance for help!

Offline

#2 03 Feb 2015 11:46

RG
Member
From: Minnesota
Registered: 18 Feb 2010
Posts: 362

Re: Batch script conect to multiple database

You might do something like this.
You don't need to enable delayed expansion. This way you can have ! in the password.
Remove the "echo." from the sqlplus statement if it looks correct.

echo off
cls
for /f   "tokens=1-2 delims= " %%b in (database.lis) do (
   echo.***********************************************
   echo.Connect to %%b
   echo. Password: %%c
   echo.***********************************************
   echo.sqlplus system/%%c@%%b @C:\scripturi\verify.sql
   pause 
)
echo.
echo.DONE
echo.Press any key to exit.
pause >nul

Windows Shell Scripting and InstallShield

Offline

#3 03 Feb 2015 12:40

platon39
Member
Registered: 24 Feb 2014
Posts: 30

Re: Batch script conect to multiple database

Hello, it worked, thanks a lot for help.

Offline

#4 05 Feb 2015 15:10

platon39
Member
Registered: 24 Feb 2014
Posts: 30

Re: Batch script conect to multiple database

But any ideea how to hide the password ?
Many thanks!

Offline

#5 05 Feb 2015 15:32

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Batch script conect to multiple database

Yeah. Don't include that echo line in the script.

Offline

#6 06 Feb 2015 12:25

platon39
Member
Registered: 24 Feb 2014
Posts: 30

Re: Batch script conect to multiple database

big_smile  I was taliking about the .lis file, of course i will not include the echo  smile.
Any way , i generated it by another script  like :
echo database   password  >>file.lis and i converted my .cmd file into .exe .I delete my .lis file after the script is done.
But i the user press Ctrl-C ,it will able to see the .lis files. So, i want this to be deleted automatically if a user
interrupt the script.
Does any one know how to make the script to 
execute  a command (like delete *.lis ) if the user presses Ctrl-C ?
Many thanks in advance for help .

Last edited by platon39 (06 Feb 2015 12:37)

Offline

#7 18 Feb 2015 13:36

platon39
Member
Registered: 24 Feb 2014
Posts: 30

Re: Batch script conect to multiple database

hello,


Does any one know how to make the script to
execute  a command (like delete *.lis ) if the user presses Ctrl-C ?
Many thanks in advance for help .

Offline

#8 18 Feb 2015 15:26

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Batch script conect to multiple database

Pressing CTRL+C interrupts the script, meaning no processing takes place after that button combination is pressed. Batch has no event handling, and therefore no way of detecting if the buttons are pressed. You could have a second script that is constantly running that monitors the tasklist and takes action if the script is terminated, but frankly, that's a terrible idea.

Also, your idea to have the database details stored in plaintext is rudimentary flawed because, well, you're storing database details in plaintext. Encrypt the data in some way (heck, even just a Vigenere cipher would work), then ask the user for the password to decrypt the data when the script is initially run.

Offline

Board footer

Powered by