|
Answer» The below code was written to eliminate the need for users to manually copy files from one location to another, instead the code will do it for the user, however I am looking for a bit more error level checking and a few more precautions before I let the rest of the staff use it. Basically we have a server that hosts client files for production, these files determine how the work they run is handle, ie breaking the work into different folders etc.
Before running this code a user has to run an institution configuration utility that lets them set up the client number. IE BC0111. My problem is I want to make sure nothing is overwritten, for example, I don't this script to be able to take input for a user account that has been around for a year for the files to be copied over. So originally I was using /d on the xcopy command, but this doesn't really work all that well, because some files when copied over are in fact older then the source.
I did create a new test client number today to SEE what files by default were created. The following files are created when the user creates the institution so would have todays date, so I was thinking I could use this to my advantage. I could check in the folder to make sure the files are not older then current system date, thus eliminating the need for /d, but would like some additional thoughts on if this would work without overwriting ANYTHING and am curious as to if this would stop users from destroying something I needed. Files are ... located in the parms dir ... addturbo.ini, adjnames.ini, banksearch.ini, date.ctl, naconfig.ini, plugbal.ini, suspnames.ini, turbo.ini, turbo.enm.ini, and turbousr.ini. The forms folder is not created when a new institution is created, it is copied over from the test environment.
It is a lot of code to read over, so if anyone has that much time to give me, I really want you to know I appreciate it. Thank you.
Code: [Select]Rem Copy Parms and Forms to Production TBCxxxx ^& BCxxxx
set M=%DATE:~4,2% set D=%DATE:~7,2% set Y=%DATE:~10,4%
set AFSBRCTEST=\\OMASUPRT3\ipsuprt\AFSInstalls\BRCTest set AFSBRCPROD=\\OMASUPRT3\ipsuprt\AFSInstalls\BRCProd set CCBRCTEST=\\OMASUPRT3\shared\ChangeControl\App\BRCTest set CCBRCPROD=\\OMASUPRT3\shared\ChangeControl\App\BRCProd
Set ProductionSrv=\\omavsuc1\d$\vision Set DevelopHost=\\topdbsrv3\c$\vision
Rem ------------------------------------------------------- Rem Copy parms and edit libs or just edit libs. cls @ECHO Go right to editing Lib files ? @ECHO. @ECHO. @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto CheckProdsrv if errorlevel 1 set var=1 & goto editlibs
Rem ------------------------------------------------------- Rem Check Production Path :CheckProdsrv @ECHO. @ECHO Is %ProductionSrv% the correct Production Path? @ECHO. @ECHO. @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto SetProdSrv if errorlevel 1 goto SetCN
Rem ------------------------------------------------------- Rem What is the Production Path? :SetProdSrv Cls Title Production Path is
set ProductionSrv= set /P ProductionSrv=Type Production Path: (EX: \\omavsuc1\d$\vision) %=% if "%ProductionSrv%"=="" goto input Cls if "%ProductionSrv%"=="exit" goto EOF @echo. @echo You Typed : %ProductionSrv% @echo. @ECHO Is this the correct selection? @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto SetProdSrv if errorlevel 1 goto SetSN
Rem ------------------------------------------------------- Rem What is the client number :SetCN Title Client Number is Cls
set CN= set /P CN=Type client number: (EX: BCxxxx) %=% if "%CN%"=="" goto input Cls if "%CN%"=="exit" goto EOF @echo. @echo You Typed Client number: %CN% @echo. @ECHO Is this the correct selection? @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto SetCN if errorlevel 1 goto continue1
Rem ------------------------------------------------------- Rem Map Drives :continue1
:PRODDrive
net use Y %ProductionSrv% /user:Fiserv\%username% if errorlevel 1 goto ErrMapProd
@echo. @echo Drive Mapped... @echo.
Rem ------------------------------------------------------- :TOPDrive
net use V %DevelopHost% /user:Fiserv\%username% if errorlevel 1 goto ErrMapTOP
@echo. @echo Drive Mapped... @echo.
Rem ------------------------------------------------------- Rem Xcopy Parms and Forms from Topdbsrv3 to ProductionSrv :IVcreated Title Coping Parms and Forms cls @echo. @ECHO Did you create the ImageVision Institution in Image Vision? @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto CreateIV if errorlevel 1 goto Proceed
:Proceed if exist %DevelopHost%\bank\T%CN% goto passed1 Echo Missing %developHost%\bank\T%CN% & sleep 4 & Goto unmap :passed1 if exist %ProductionSrv%\bank\T%CN% goto passed2 Echo Missing %ProductionSrv%\bank\T%CN% & sleep 4 & Goto unmap :passed2 xcopy %DevelopHost%\bank\T%CN%\Parms %ProductionSrv%\bank\T%CN%\Parms /D /Y
Rem Xcopy Parms and Forms from IRDTEMPLATE xcopy %ProductionSrv%\irdimagetemplates\Parms %ProductionSrv%\bank\T%CN%\Parms /D /Y xcopy %ProductionSrv%\irdimagetemplates\Forms %ProductionSrv%\bank\T%CN%\Forms /D /Y
Rem Delete Date.ctl cd\ Y: cd bank\T%CN%\Parms Echo Deleting Date.ctl from %ProductionSrv%\bank\T%CN%\Parms & sleep 3 & Del /P Date.ctl
Rem ------------------------------------------------------- Rem Confirm programmer asked for Production to have Parms copied :LiveProd Title ¿ Programmer Confirm ? cls @echo. @ECHO Did programmer request we WAIT to copy parms/forms to %ProductionSrv%\bank\%CN% ? @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto Proceed1 if errorlevel 1 goto unmap Rem Xcopy Parms and Forms from ProductionSrv\testbank to ProductionSrv\livebank :Proceed1 if exist %ProductionSrv%\bank\%CN% goto passed3 Echo Missing %ProductionSrv%\bank\%CN% & sleep 4 & Goto unmap :passed3 if exist %ProductionSrv%\bank\%CN% goto passed4 Echo Missing %ProductionSrv%\bank\%CN% & sleep 4 & Goto unmap :passed4 xcopy %ProductionSrv%\bank\T%CN%\Parms %ProductionSrv%\bank\%CN%\Parms /D /Y xcopy %ProductionSrv%\bank\T%CN%\Forms %ProductionSrv%\bank\%CN%\Forms /D /Y
Rem Delete Date.ctl cd\ Y: cd bank\%CN%\Parms Echo Deleting Date.ctl from %ProductionSrv%\bank\%CN%\Parms & sleep 3 & Del /P Date.ctl
Rem ------------------------------------------------------- :CreateIV cls Echo Sleeping for 30 seconds, please create Institution in Image Vision Sleep 30 Goto IVcreated
Rem ------------------------------------------------------- Rem Edit Lib files (Change Control) :Editlibs @echo. @ECHO Do you wish to AUTOMATICALLY edit the lib files? @ECHO. @ECHO. @ECHO **NOTE** Will currently only work for ProductionHost 'omavsuc1' @ECHO. @ECHO Files were editing are ... @ECHO %AFSBRCPROD%\Libs.ini @ECHO %AFSBRCTEST%\Libs.ini @ECHO %CCBRCPROD%\Libs.ini @ECHO %CCBRCTEST%\Libs.ini @ECHO. @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto unmap if errorlevel 1 goto edit
:edit
Rem What is the client number If %var% EQU 1 goto libCN goto setclientname :libCN Title Client Number is Cls
set CN= set /P CN=Type client number: (EX: BCxxxx) %=% if "%CN%"=="" goto input Cls if "%CN%"=="exit" goto EOF @echo. @echo You Typed Client number: %CN% @echo. @ECHO Is this the correct selection? @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto libcn if errorlevel 1 goto setclientname
:setclientname Title Clientname is Cls
set Clientname= set /P Clientname=What is the client name?: (EX: TierOne) %=% if "%Clientname%"=="" goto input Cls if "%Clientname%"=="exit" goto EOF @echo. @echo Clientname is : %Clientname% @echo. @ECHO Is this the correct ClientName for %CN%? @ECHO (Y) - YES (N) - NO
CHOICE /c:YN /M( /N
if errorlevel 2 goto setclientname if errorlevel 1 goto backup
:backup Rem Backup all files first xcopy %AFSBRCPROD%\libs.ini %AFSBRCPROD%\Libs_Save\libs.%m%%d%%y%.ini /D /Y xcopy %AFSBRCTEST%\libs.ini %AFSBRCTEST%\Libs_Save\libs.%m%%d%%y%.ini /D /Y xcopy %CCBRCPROD%\libs.ini %CCBRCPROD%\Libs_Save\libs.%m%%d%%y%.ini /D /Y xcopy %CCBRCTEST%\libs.ini %CCBRCTEST%\Libs_Save\libs.%m%%d%%y%.ini /D /Y Rem Check first if Files have been updated Find /I "%CN%" %AFSBRCPROD%\libs.ini If errorlevel 1 Echo %AFSBRCPROD%\libs.ini needs editing & sleep 2 & goto check2 Echo No edit needed for %AFSBRCPROD%\libs.in & sleep 3 & Set AFSBRCPROD=1 :check2 Find /I "%CN%" %AFSBRCTEST%\libs.ini If errorlevel 1 Echo %AFSBRCTEST%\libs.ini needs editing & sleep 2 & goto check3 Echo No edit needed for %AFSBRCTEST%\libs.in & sleep 3 & Set AFSBRCTEST=1 :check3 Find /I "%CN%" %CCBRCPROD%\libs.ini If errorlevel 1 Echo %CCBRCPROD%\libs.ini needs editing & sleep 2 & goto check4 Echo No edit needed for %CCBRCPROD%\libs.in & sleep 3 & Set CCBRCPROD=1 :check4 Find /I "%CN%" %CCBRCTEST%\libs.ini If errorlevel 1 Echo %CCBRCTEST%\libs.ini needs editing & sleep 2 & goto startedit Echo No edit needed for %CCBRCTEST%\libs.in & sleep 3 & Set CCBRCTEST=1
Rem Create holders of current data for append to top dos command :startedit
If %AFSBRCPROD% NEQ 1 Type %AFSBRCPROD%\libs.ini > %AFSBRCPROD%\holder.ini If errorlevel 1 goto Failed
If %AFSBRCTEST% NEQ 1 Type %AFSBRCTEST%\libs.ini > %AFSBRCTEST%\holder.ini If errorlevel 1 goto Failed
If %CCBRCPROD% NEQ 1 Type %CCBRCPROD%\libs.ini > %CCBRCPROD%\holder.ini If errorlevel 1 goto Failed
If %CCBRCTEST% NEQ 1 Type %CCBRCTEST%\libs.ini > %CCBRCTEST%\holder.ini If errorlevel 1 goto Failed
Rem Add data to lib files
If %AFSBRCPROD% EQU 1 goto skipedit Echo [%CN% Parms]>%AFSBRCPROD%\libs.ini Echo Description=%CN% %Clientname%>>%AFSBRCPROD%\libs.ini Echo Xfer=FTP>>%AFSBRCPROD%\libs.ini Echo Center=BRC>>%AFSBRCPROD%\libs.ini Echo Type=Parms>>%AFSBRCPROD%\libs.ini Echo DevlpHost=OMAVSUC1>>%AFSBRCPROD%\libs.ini Echo ProdHost=OMAVSUC1>>%AFSBRCPROD%\libs.ini Echo TypeDir=%CN%_Parms>>%AFSBRCPROD%\libs.ini Echo DevlpPath=D:\Vision\Bank\T%CN%\Parms>>%AFSBRCPROD%\libs.ini Echo ProdPath=D:\Vision\Bank\%CN%\Parms>>%AFSBRCPROD%\libs.ini Echo.>>%AFSBRCPROD%\libs.ini
Type %AFSBRCPROD%\holder.ini >> %AFSBRCPROD%\libs.ini Echo Delete holder.ini & Sleep 2 Del %AFSBRCPROD%\holder.ini
:skipedit If %AFSBRCTEST% EQU 1 goto skipedit1 Echo [T%CN% Parms]>%AFSBRCTEST%\libs.ini Echo Description=T%CN% %Clientname%>>%AFSBRCTEST%\libs.ini Echo Xfer=FTP>>%AFSBRCTEST%\libs.ini Echo Center=BRC>>%AFSBRCTEST%\libs.ini Echo Type=Parms>>%AFSBRCTEST%\libs.ini Echo DevlpHost=TOPDBSRV3>>%AFSBRCTEST%\libs.ini Echo ProdHost=OMAVSUC1>>%AFSBRCTEST%\libs.ini Echo TypeDir=T%CN%_Parms>>%AFSBRCTEST%\libs.ini Echo DevlpPath=C:\Vision\Bank\T%CN%\Parms>>%AFSBRCTEST%\libs.ini Echo ProdPath=D:\Vision\Bank\T%CN%\Parms>>%AFSBRCTEST%\libs.ini Echo.>>%AFSBRCTEST%\libs.ini
Type %AFSBRCTEST%\holder.ini >> %AFSBRCTEST%\libs.ini Echo Delete holder.ini & Sleep 2 Del %AFSBRCTEST%\holder.ini
:skipedit1 If %CCBRCPROD% EQU 1 goto skipedit2 Echo [%CN% Parms]>%CCBRCPROD%\libs.ini Echo Description=%CN% %Clientname% >>%CCBRCPROD%\libs.ini Echo Xfer=FTP>>%CCBRCPROD%\libs.ini Echo Center=BRC>>%CCBRCPROD%\libs.ini Echo Type=Parms>>%CCBRCPROD%\libs.ini Echo DevlpHost=OMAVSUC1>>%CCBRCPROD%\libs.ini Echo ProdHost=OMAVSUC1>>%CCBRCPROD%\libs.ini Echo TypeDir=%CN%_Parms>>%CCBRCPROD%\libs.ini Echo DevlpPath=D:\Vision\Bank\T%CN%\Parms>>%CCBRCPROD%\libs.ini Echo ProdPath=D:\Vision\Bank\%CN%\Parms>>%CCBRCPROD%\libs.ini Echo.>>%CCBRCPROD%\libs.ini
Type %CCBRCPROD%\holder.ini >> %CCBRCPROD%\libs.ini Echo Delete holder.ini & Sleep 2 Del %CCBRCPROD%\holder.ini
:skipedit2 If %CCBRCTEST% EQU 1 goto unmap Echo [T%CN% Parms]>%CCBRCTEST%\libs.ini Echo Description=T%CN% %Clientname%>>%CCBRCTEST%\libs.ini Echo Xfer=FTP>>%CCBRCTEST%\libs.ini Echo Center=BRC>>%CCBRCTEST%\libs.ini Echo Type=Parms>>%CCBRCTEST%\libs.ini Echo DevlpHost=TOPDBSRV3>>%CCBRCTEST%\libs.ini Echo ProdHost=OMAVSUC1>>%CCBRCTEST%\libs.ini Echo TypeDir=T%CN%_Parms>>%CCBRCTEST%\libs.ini Echo DevlpPath=C:\Vision\Bank\T%CN%\Parms>>%CCBRCTEST%\libs.ini Echo ProdPath=D:\Vision\Bank\T%CN%\Parms>>%CCBRCTEST%\libs.ini Echo.>>%CCBRCTEST%\libs.ini
Type %CCBRCTEST%\holder.ini >> %CCBRCTEST%\libs.ini Echo Delete holder.ini & Sleep 2 Del %CCBRCTEST%\holder.ini
Rem ------------------------------------------------------- Rem un-Map Drives :unmap
:unPRODDrive
net use Y /delete %ProductionSrv% if errorlevel 1 goto ErrMapunProd
@echo. @echo Drive un-Mapped... @echo.
Rem ------------------------------------------------------- :unTOPDrive
net use V /delete %DevelopHost% if errorlevel 1 goto ErrMapunTOP
@echo. @echo Drive un-Mapped... @echo. Goto EOF
Rem ------------------------------------------------------- Rem Error Mapping Drives
:ErrMapProd Echo Error Mapping %ProductionSrv% & Pause & exit
:ErrMapTOP Echo Error Mapping %DevelopHost% & Pause & exit
Rem ------------------------------------------------------- Rem Error Mapping Drives
:ErrMapunProd Echo Error un-Mapping %ProductionSrv% & Pause & exit
:ErrMapunTOP Echo Error un-Mapping %DevelopHost% & Pause & exit
:EOF Echo Utility Closing, thank you for using, have a nice day. Title Goodbye Sleep 5 Exit
Rem ------------------------------------------------------- :Failed
Echo Creating holder libs file failed, manually check and edit files. sleep 4 exitThinking this through a bit more, is it possible to pull the date from a file? I was wondering, could you run the 'dir' command to a output then use this file to determine the date or is there another way? Code: [Select]@ECHO ON
Set root=%CD%
Set dirfile=%CD%
set M=%DATE:~4,2% set D=%DATE:~7,2% set Y=%DATE:~10,4%
rem dir "%dirfile%\dir" >dir.txt rem set filename="%dirfile%\dir.txt"
rem type %filename% | find "turbo.ini"
for /f "tokens=*" %I in ('dir "%dirfile%\dir"') do @echo date=%I
Pause Figure no one wanted to read the rest of my messy code, this is what i'm look at to pull out the date information but for some reason I can't get it to work. Any ideas? Right now it just ends the batch file so I'm assuming the syntax is wrong. I probably don't really need to to echo 'date=' but doesn't work even when taking that out. Once I get the date from this for statement how do I go about comparing it to the current date?
if date EQU date command ? Is there good reason you aren't just holding all of the existing client IDs in a file and checking to see if the requested ID already exists in that file before creating it? I would think that would be the idea way to ensure no duplicate IDs are created....Good idea and I had thought about doing something like that, then just searching the file, but the issue I would have there is what happens if the file gets blitzed. I guess I could do a back up file and do a check on if it exists, but I guess I am more curious how to get this to work. Ok, dunno how applicable this is for your situation, but you can download the Win2k pack that has a version of the GREP command for Dos called QGREP. http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en You can then get GAWK which is a DOS port of AWK from here http://gnuwin32.sourceforge.net/packages/gawk.htm Then you can then pipe the dir command to Grep and AWK the results, something like this: "dir|qgrep filename|gawk '{print $1 $6 $7 $8}' > filedates.txt"
That lists all of the files in a directory, gets their names, and the datestamp on them, and writes them to a text file. You can then do a list compare so long as the dates are in the same format. The downside is that you have to have gawk and qgrep installed WHEREVER the script is used. I don't know if that's a problem for your situation or not. Not in this situation as the script will probably be run from different locations and not all of them do I have admin rights to.
I was thinking of doing this another way, is there a way to figure out the item count? When creating I always get 8 files I could put a stop in the bat file to error out if more then 8 files, then I don't have to worry about my file with the list of client numbers getting blitzed.
I would still like to learn how to pull the date out of a file if anyone is willing to point me in the right direction, but for now the above sounds like a more promising idea. Think I have something that will work. Seems to anyway ... anyone have ideas to improve my code? Also anyone have code tidbits on the original request of Pulling the date from the files in the directory?
Code: [Select]@echo off set source=%cd%
rem pushd "%source%" set /a count=0 for /f "delims=" %%a in ('dir /b /a:-d /o:-d 2^>NUL') do call :PROCESS "%%a" rem popd goto :check
:PROCESS if %count%==9 Echo Failed & Pause & Goto Failed set /a count+=1 Echo. Echo Count is %Count% goto :check
:CHECK if %count%==8 Echo Correct number of files in directory(Count:%count%) & goto continueCode: [Select]pushd %ProductionSrv%\bank\T%CN% Set /a count=0 for /f "delims=" %%a in ('dir /b /a:-d /o:-d 2^>NUL') do call :PROCESS "%%a" popd goto :check
:PROCESS set /a count+=1 Echo Count is %Count% goto :check
:CHECK IF /I %Count% GTR 10 Echo Bypassing xcopy step from %DevelopHost%\bank\T%CN%\Parms to %ProductionSrv%\bank\T%CN%\Parms>>%log% & set Prodcopy=1 & goto LiveProd ELSE Goto :Xcopy1 Looks like I was wrong, the code doesn't seem to work, anyone know why? In the code I have 'goto :check' if I have it as 'goto check' it doesn't work either. For some reason after it runs it wants to end the batch file, at least in my test run.
**Test File** Code: [Select]@echo on
set source=\\omavsuc1\d$\Vision\test\parms
pushd "%source%" set /a count=0 for /f "delims=" %%a in ('dir /b /a:-d /o:-d 2^>NUL') do call :PROCESS "%%a" popd goto :eof
:PROCESS set /a count+=1 Echo Count is %count% & sleep 1 goto :eof
:eof if /I %count% GTR 10 Echo Count equals %count% & Pause Echo EOF & Pause & Exit It doesn't even seen to go to EOF, it just counts the number of files then ends. Any ideas? The goto :eof transfers control to the end of the current batch file. This is an easy way to exit a batch file without defining a label. It is also used to exit from a subroutine.
Code: [Select]@echo on
set source=\\omavsuc1\d$\Vision\test\parms
pushd "%source%" set /a count=0 for /f "delims=" %%a in ('dir /b /a:-d /o:-d 2^>NUL') do call :PROCESS "%%a" popd goto :end
:PROCESS set /a count+=1 Echo Count is %count% & sleep 1 goto :eof
:end if /I %count% GTR 10 Echo Count equals %count% & Pause Echo EOF & Pause & Exit
Quote from: Sidewinder on July 16, 2008, 02:00:58 PM The goto :eof transfers control to the end of the current batch file. This is an easy way to exit a batch file without defining a label. It is also used to exit from a subroutine.
Code: [Select]@echo on
set source=\\omavsuc1\d$\Vision\test\parms
pushd "%source%" set /a count=0 for /f "delims=" %%a in ('dir /b /a:-d /o:-d 2^>NUL') do call :PROCESS "%%a" popd goto :end
:PROCESS set /a count+=1 Echo Count is %count% & sleep 1 goto :eof
:end if /I %count% GTR 10 Echo Count equals %count% & Pause Echo EOF & Pause & Exit
Let me make sure I understand this ...
Basically by starting the For loop we need to stop it similar to regular VB, so by saying 'goto :end' we're saying that once the For loop is complete you can process any other Goto commands outside of the process we called?
The 'goto :eof' ... would that really ever be called as a real goto command as I do have ':eof' as a section of my code. The goto end statement has nothing to do with the for loop. It's used to prevent the code from falling into the :process logic.
The goto :eof statement exits the :process subroutine. Using a call to an internal label creates a new batch file context. Arguments (if any) are referenced as command line parameters (see call /? for details). In this context, it acts as a return mechanism to the next instruction after the call. (in your case it would be the next iteration of the for loop)
Using a goto :eof not in the context of a subroutine, branches to the end of the batch file.
Bottom line is do not create labels named :eof
Microsoft has a wealth of information in their help feature: command /?Thank you for that information. I was able to get it to work.
You wouldn't know how to pull the date out of a file would you? That was my original request of this topic, this does work, but I'm the type of person that love having the information in case I need it later. Thanks for all your help Sidewinder. QuoteYou wouldn't know how to pull the date out of a file would you
Which date? Files have three dates as properties (Last Written, Last Access, Creation) or is this date embedded in the file?
Comparing dates require a YYYYMMDD format, so if your default format is something else, you'll need to do some data manipulation. Batch code does not do date/time arithmetic unless you are prepared to write a boatload of if statements.
As poster's requests become more sophisticated, it becomes necessary to move from a command language to a script language. Microsoft seems to have made the Visual Basic family the official language of Windows. Perhaps you will consider VBScript.
I was looking for the creation date of the file, then comparing this to current system date.
VBscript might be a possibility, just haven't messed with it that much yet.
|