【发布时间】:2014-09-16 14:00:55
【问题描述】:
好的,所以我正在编写一个批处理文件,通过替换客户端上的文件来帮助客户端迁移。
@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 并执行代码之外,大多数事情都可以工作:
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 **& 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 和标签
那么,有人有想法吗?
【问题讨论】:
标签: windows batch-file if-statement for-loop exists