You are not logged in.
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
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
Hello, it worked, thanks a lot for help.
Offline
But any ideea how to hide the password ?
Many thanks!
Offline
Yeah. Don't include that echo line in the script.
Offline
I was taliking about the .lis file, of course i will not include the echo .
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
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
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