2014-09-16 2 views
0

좋아요, 그래서 클라이언트의 파일을 대체하여 클라이언트 마이그레이션을 돕기 위해 배치 파일을 작성하고 있습니다. 올바른 코드 현명한 그러나 내가 그것을 뛰어 넘고 싶은FOR 및 IF 존재 및 고토 문제가있는 Windows 일괄 처리

ECHO Could not find SEP on client %%v 
ECHO %%v >> %LIST%%N2% 

이된다

@ECHO OFF 
ECHO Only type "clients" or "servers" 
SET /P TYPE=clients or servers: 
SET /P LIST=%TYPE% list filename: 
SET /P SITE=Site: 
SET SYMPATH="" 
SET LIST2="" 
SET N= 
SET N2=0 
Echo This will migrate %TYPE% in site %SITE% from list %LIST%, correct? 
PAUSE 
:STRT 
SET /a N2=N2+1 
SET LIST2=%LIST%%N% 
FOR /F "tokens=*" %%v IN (%LIST2%) DO (
ECHO Checking %%v... 
SET COMP=%%v 
if exist "\\%%v\c$\program files (x86)\symantec\symantec endpoint protection\smc.exe" SET "SYMPATH=program files (x86)\symantec\symantec endpoint protection" & CALL :MIGRATE 
if exist "\\%%v\c$\program files\symantec\symantec endpoint protection\smc.exe" SET "SYMPATH=program files\symantec\symantec endpoint protection" & CALL :MIGRATE 
if exist "\\%%v\c$\program files (x86)\symantec antivirus\smc.exe" SET "SYMPATH=program files (x86)\symantec antivirus" & CALL :MIGRATE 
if exist "\\%%v\c$\program files\symantec antivirus\smc.exe" SET "SYMPATH=program files\symantec antivirus" & CALL :MIGRATE 
ECHO Could not find SEP on client %%v 
ECHO %%v >> %LIST%%N2% 
) 
:MIGRATE 
ECHO Migrating %COMP%... 
psexec \\%COMP% -h "c:\%SYMPATH%\smc.exe" -p xxxxxx -stop 
copy "%TYPE%_xml\My Company_Workplace_%TYPE%_%SITE%_sylink.xml" "\\%COMP%\c$\%SYMPATH%\SyLink.xml" /Y 
psexec \\%COMP% -h "c:\%SYMPATH%\smc.exe" -start 
ECHO Migrated %COMP% to SEP12 group %SITE% >> END_%SITE%.log 
ECHO Migrated %COMP% to SEP12 group %SITE% 
EXIT /b 
SET /a N=N+1 
ECHO End of the list, starting over with %LIST2% 
GOTO STRT ` 

대부분의 일을 제외하고 일하는 클라이언트는 CALL로 다시 이동하고 코드를 실행 마이그레이션 한 후 이 2 개 라인과 같이, 다음 클라이언트를 계속 :

@ECHO OFF 
ECHO Only type "clients" or "servers" 
SET /P TYPE=clients or servers: 
SET /P LIST=%TYPE% list filename: 
SET /P SITE=Site: 
SET SYMPATH="" 
SET LIST2="" 
SET N= 
SET N2=0 
Echo This will migrate %TYPE% in site %SITE% from list %LIST%, correct? 
PAUSE 
:STRT 
SET /a N2=N2+1 
SET LIST2=%LIST%%N% 
FOR /F "tokens=*" %%v IN (%LIST2%) DO (
ECHO Checking %%v... 
SET COMP=%%v 
if exist "\\%%v\c$\program files (x86)\symantec\symantec endpoint protection\smc.exe" SET "SYMPATH=program files (x86)\symantec\symantec endpoint protection" & CALL :MIGRATE **& GOTO :NEXT** 
if exist "\\%%v\c$\program files\symantec\symantec endpoint protection\smc.exe" SET "SYMPATH=program files\symantec\symantec endpoint protection" & CALL :MIGRATE **& GOTO :NEXT** 
if exist "\\%%v\c$\program files (x86)\symantec antivirus\smc.exe" SET "SYMPATH=program files (x86)\symantec antivirus" & CALL :MIGRATE **& GOTO :NEXT** 
if exist "\\%%v\c$\program files\symantec antivirus\smc.exe" SET "SYMPATH=program files\symantec antivirus" & CALL :MIGRATE **& GOTO :NEXT** 
ECHO Could not find SEP on client %%v 
ECHO %%v >> %LIST%%N2% 
**:NEXT** 
) 
:MIGRATE 
ECHO Migrating %COMP%... 
psexec \\%COMP% -h "c:\%SYMPATH%\smc.exe" -p xxxxxx -stop 
copy "%TYPE%_xml\My Company_Workplace_%TYPE%_%SITE%_sylink.xml" "\\%COMP%\c$\%SYMPATH%\SyLink.xml" /Y 
psexec \\%COMP% -h "c:\%SYMPATH%\smc.exe" -start 
ECHO Migrated %COMP% to SEP12 group %SITE% >> END_%SITE%.log 
ECHO Migrated %COMP% to SEP12 group %SITE% 
EXIT /b 
SET /a N=N+1 
ECHO End of the list, starting over with %LIST2% 
GOTO STRT ` 

을하지만 난 (코드 블록에서 GOTO 라벨을 사용할 수 없기 때문에이 작동하지 않습니다)

그래서 누구나 아이디어가 있습니까?

답변

2
FOR /F "tokens=*" %%v IN (%LIST2%) DO (
    ... 
    SET "SYMPATH=" 
    if exist "\\%%v\c$\..." SET "SYMPATH=..." & CALL :MIGRATE 
    if exist "\\%%v\c$\..." SET "SYMPATH=..." & CALL :MIGRATE 
    if exist "\\%%v\c$\..." SET "SYMPATH=..." & CALL :MIGRATE 
    if exist "\\%%v\c$\..." SET "SYMPATH=..." & CALL :MIGRATE 

    if not defined SYMPATH (
     ECHO Could not find SEP on client %%v 
     ECHO %%v >> %LIST%%N2% 
    ) 
) 

각 반복마다 sympath을 재설정하고 테스트를 수행하십시오. 마지막에 변수가 정의되지 않은 경우 일치하는 항목이 없습니다.

+0

고마워요! 마지막으로 테스트 해 보니 솔루션이 작동합니다! –

0
for /f "tokens=*" %%v IN (%LIST2%) do (
    echo Checking %%v... 
    set "COMP=%%~v" 
    set "SYMPATH=" 
    for %%P in (
    "program files (x86)\symantec\symantec endpoint protection" 
    "program files\symantec\symantec endpoint protection" 
    "program files (x86)\symantec antivirus\smc.exe" 
    "program files\symantec antivirus" 
) do if not defined SYMPATH if exist "\\%%v\c$\%%~P" (
    set "SYMPATH=%%~p" 
    call :MIGRATE 
) 
    if not defined SYMPATH (
    echo Could not find SEP on client %%v 
    echo %%v >> %LIST%%N2% 
) 
) 
+0

네, 입력 해 주셔서 감사합니다. –