Solved Getting a user input, storing it, and reusing it.

June 19, 2012 at 07:48:59
Specs: Windows XP
Hey everyone,

I am working on a batch script/program that automates some regular day-to-day operations, DDL Deployments to be more precise.
The sql files that need to be executed are done so for different environments, meaning that their LOCATION is the same, and the the beginning part of their NAMEs are the same but have different endings like dev for developers, off for offshore and so. Ex: 13_july_2012_amt_DEV.sql,
13_july_2012_amt_OFF.sql and so on.
So, i would like my program/script to ask for a the file location once and the file name (the exact same part of the name) once and store it in some file and go and grab it when it needs to execute the next sql. Makes sense?
Here is the part of what I have for it:
...

SET /P fileloc=Enter the file directory^>
ECHO.%fileloc%> d:\temporary\Deploy\filedir.txt
SET /P fileloc=< d:\temporary\Deploy\filedir.txt

SET /P filenm=Enter the file name^>
ECHO.%filenm%> d:\temporary\Deploy\filedir.txt
SET /P filenm=< d:\temporary\Deploy\filedir.txt

ECHO Please enter the file directory followed by the file name:
ECHO .RUN FILE c:\dxr\someDDL\%fileloc%\%filenm%_DEV.sql; >> run_dev.txt
...
Any suggestions?

Thanks in advance!


See More: Getting a user input, storing it, and reusing it.

Report •

#1
June 19, 2012 at 13:26:56
✔ Best Answer
::perhaps this will aid
::sets variable "fileloc" file location
SET /P fileloc="Enter the file directory^>"
::stores %fileloc% into whatever file you have
ECHO.%fileloc%> c:\filedir.txt
::pulls data from file. sets it to %fileloc%
for /f "tokens=*" %%G IN (c:\filedir.txt) DO SET fileloc=%%G
::mike

:: mike


Report •

#2
June 19, 2012 at 13:28:09
I should add that this doesnt check to see if the directory exists, it assumes that, untested as well.

:: mike


Report •

#3
June 20, 2012 at 12:34:37
Thanks, mikelinus!
I think it worked.

However, now I have another question/issue:
I am trying to make my script to go and read the log file that is created after running the script, and check for a errors (in this case, particular set of strings) and respond accordingly. But, it is not reading it for some reason.
This is what I have so far:


@ECHO OFF
ECHO.
ECHO -+-+- Ready for DDL Deployment -+-+-
ECHO.

DEL c:\automatic_deployment\runfile_dev.txt

REM Loggin on and appending that process to the newly created file
ECHO .LOGON someprogram/pswrd,usernm; >> runfile_dev.txt

REM Setting a maximum error severity level beyond which BTEQ terminates job processing
ECHO .SET maxerror 1 ; >> runfile_dev.txt

SET /P fileloc=Enter the file directory^>
ECHO.%fileloc%> c:\automatic_deployment\filedir.txt
for /f "tokens=*" %%G IN (c:\automatic_deployment\filedir.txt) DO SET fileloc=%%G

SET /P filenm=Enter the file name^>
ECHO.%filenm%> c:\automatic_deployment\filename.txt
for /f "tokens=*" %%G IN (c:\automatic_deployment\filename.txt) DO SET filenm=%%G

REM Script should retrieve those file location and names and use them here
ECHO .RUN FILE C:\%fileloc%\%filenm%.sql; >> runfile_dev.txt

TYPE c:\automatic_deployment\bteq_error_Handling.txt >> c:\automatic_deployment\runfile_dev.txt

bteq < c:\automatic_deployment\runfile_dev.txt >> C:\automatic_deployment\%filenm%_DEV_Log.txt 2>&1

ECHO Checking the log file for errors...
FINDSTR /m "Successful DDL Deployment" "C:\automatic_deployment\%filenm%_DEV_Log.txt"
IF %errorlevel%<>0 (
ECHO Deployment was not successfull. Errors were found!
GOTO failmail
)
ECHO Deployment was a success. No errors were found!
GOTO successmail

:failmail
ECHO Emailing the admin...
cscript //NoLogo //B fail_mail.vbs
GOTO exit

:successmail
ECHO Emailing the admin...
cscript //NoLogo //B success_mail.vbs
GOTO exit

pause


Once it checks the log files and finds errors, i am making it call my fail_mail.vbs that sends the error mail to the admin, otherwise, calls the success_mail.vbs that will send success message to the admin.
Can you take a look and see what is wrong with that FINDSTR and the overall script(i'm sure it's not that professional)?

Thanks in advance!


Report •

Related Solutions

#4
June 20, 2012 at 13:16:53
There is no <> operator like in T-SQL. You need to use neq or the not keyword.

IF %errorlevel% neq 0 (
ECHO Deployment was not successfull. Errors were found!
GOTO failmail
)

or

IF NOT errorlevel 0 (
ECHO Deployment was not successfull. Errors were found!
GOTO failmail
)

Here is how I would do it:

FINDSTR /m "Successful DDL Deployment" "C:\automatic_deployment\%filenm%_DEV_Log.txt" || ECHO Deployment was not successfull. Errors were found! &&
GOTO failmail

Tony


Report •

#5
June 20, 2012 at 13:59:18
Thanks, Tony!

I used that exact same line that you provided at the end there. However, I am getting 2 emails: success and fail. I assumed this would happen. But, gave it a shot.
Because, in that FINDSTR line before the '||' sign, don't I need to call the successmail?

I'm gonna try the 2 options above now. let's see :)


Report •

#6
June 20, 2012 at 14:11:08
I think it is working now. (At least, the emailing part :)
Here is what I did:

FINDSTR /m "Successful DDL Deployment" "C:\%fileloc%\%filenm%_DEV_Log.txt"
IF %errorlevel% neq 0 (
ECHO Deployment was not successfull. Errors were found!
ECHO Emailing the admin...
start fail_mail.vbs
)

PING 1.1.1.1 -n 1 -w 500 >NUL
pause

IF &errorlevel% 0(
ECHO Emailing the admin...
start success_mail.vbs
)

PING 1.1.1.1 -n 1 -w 500 >NUL
pause

btw, ignore those "PING"s. I just used them to slow things, for testing purposes only, haha.

Thanks for the help. I think that is it for now. I will be back shortly though :)


Report •

#7
June 20, 2012 at 14:12:39
You don't have a label defined for :exit. Instead of defining your own exit label you can use the built-in :eof label.

Change:

GOTO exit

to

GOTO :eof

Tony


Report •

#8
June 20, 2012 at 14:30:15
yep tonysathre makes lots of sense, sorry i missed the second question. apparently i closed mycomputing.net buddy, so didnt notice. :-) Glad tonysathre got things running for you

:: mike


Report •

#9
June 20, 2012 at 14:39:30
Everything is working so far. Thanks mikelinus & tonysathre!
Be back soon :)

Report •

#10
June 21, 2012 at 08:30:50
mikelinus & tony

Could you, please, take a look at this .vbs related post for me?
http://www.computing.net/answers/pr...

I am sure you know something about this :)

Thanks in advance.


Report •

Ask Question