@echo off
@echo ==========================
==========
==========
==========
==========
===
@Echo Script to Copy DST patch on all servers from D:\DSTMain\Remove folder
@echo ==========================
==========
==========
==========
==========
===
@echo Please Enter Server List Path (e.i. D:\DSTMain\Srvlist\mgmsrv.
txt)
set /P srvlist=" "
IF exist %srvlist% (
Echo Server list found: %srvlist%
Echo Processing all the servers from %srvlist%
CLS
) ELSE (
CLS
Echo Server list NOT found: %srvlist%
Echo Exiting...
goto:EOF
)
IF exist D:\DSTMAIN\HostsAlive.txt Del D:\dstmain\HostsAlive.txt
IF exist D:\DSTMAIN\HostsDown.txt Del D:\dstmain\HostsDown.txt
FOR /F "TOKENS=*" %%a IN (%srvlist%) DO CALL:DONOW "%%a"
:DONOW
SET srvname=%~1
CLS
Echo 1.Processing Server: %srvname%
Echo 2.Checking Connectivity..............
.
IF exist D:\DSTMAIN\pingresult.txt Del D:\dstmain\pingresult.txt
Ping -n 1 %srvname% > PingResult.txt 2>&1
SET PingSrv=""
FOR /F "TOKENS=1,2" %%c IN ('FIND /i "Reply From" PingResult.txt') DO SET PingSrv="%%c %%d"
@ echo %PingSrv%
@ echo "%%c %%d"
PAUSE
PAUSE
PAUSE
IF "%PingSrv" == "Reply From" (
Echo 3.Reply received from Host %srvname%
Echo %srvname% >> HostsAlive.txt
REM This is to check wether currently logged in user have access or not.
IF exist D:\DSTMain\Access.txt Del D:\DSTMain\Access.txt
IF exist D:\DSTMain\NoAccess.txt Del D:\DSTMain\NoAccess.txt
Echo 4.Checking Access for Currently Logged on user on Server: %srvname%
DIR \\%srvname%\C$ > Access.txt 2>&1
FOR /F "TOKENS=1,2" %%h IN ('find /i "Logon failure:" ^< access.txt') Do SET FPA="%%h %%i"
IF /i "%FPA%" == "Logon failure:" (
Echo 5.Currently Logged in user DON'T have access to copy DST Folder.
Echo No access to Server: %srvname% >> NoAccess.txt
PAUSE
) ELSE (
REM ******** START NOW ******
Echo 5.Currently Logged in user have access to copy DST Folder.
Echo 6.Copying DST Removal folder to server: %srvname%.
MD \\%srvname%\c$\DSTRemove > DSTFolder.txt 2>&1
FIND /i "A subdirectory or file" < DSTFolder.txt > DSTFolderTest.txt 2>&1
IF "%errorlevel%" == "0" (
Copy D:\DSTMain\Remove\*.* \\%srvname%\c$\DSTRemove > DSTFiles.txt 2>&1
Echo 7.DSTRemove folder was copied successfully on server %srvname%
Echo DSTRemove Folder copied on server: %srvname% >> Success.txt
) ELSE (
Echo DST Folder already Exist for server: %srvname% >> DSTAlready.txt
)
)
) ELSE (
Echo %srvname% >> HostsDown.txt
Echo 3.Reply NOT received from Host %srvname%
)
:eof
I'm running above batch file to copy DSTFolder to our all servers. However, I'm getting error message:
The message I get:
1. Processing Server Server_name.
2. Checking Connectivity......
ACCESS.TXT"" was unexpected at this time.
Is there any way to read a word from a Text file using any other command or method except FOR /F loop?