@echo off
set LocalPath=%~dp0
cd /d "%LocalPath%"
:: 1. Packages distribution
:: 2. Remote execute batch
:: %%a - tokens[1]
:: %%b - tokens[2]
:: %%c - tokens[3]
for /f "tokens=1,2,3 delims=, " %%a in (config.txt) do (
echo PRESS ANY KEY TO DEPLOY NEXT SERVER... & pause > nul
echo deploy %%a...
call:DistributePackage %%a %%b
call:remoteexecute_single %%a %%b %%c
)
echo.&goto:eof
:DistributePackage -- Distribute package to specific path
:: -- %~1: ServerName
:: -- %~2: BatPath
:: Starting logs
if not exist Log (
mkdir Log
)
set LOGFILE=Log\%~1.log
echo Start at %DATE%%TIME% >>%LOGFILE% 2>&1
echo Log is ready >>%LOGFILE% 2>&1
echo ******************************************************************** >>%LOGFILE% 2>&1
echo **** Start Scripts **************** >>%LOGFILE% 2>&1
echo ******************************************************************** >>%LOGFILE% 2>&1
if "%~1" equ "localhost" (
goto:eof
)
set "RPath=%~2"
set "RPath=%RPath::=$%"
xcopy Package \\%~1\%RPath% /i /e /y /r >>%LOGFILE% 2>&1
goto:eof
:remoteexecute_single -- Remote execute batch command
:: -- %~1: ServerName
:: -- %~2: BatPath
:: -- %~2: BatName
SETLOCAL
set "ServerName=%1"
set "BatPath=%2"
set "BatName=%3"
:: Use current login user to execute below command
if "%~1" equ "localhost" (
CMD /C "CD /D %BatPath% & %BatName%" >>%LOGFILE% 2>&1
)
if "%~1" neq "localhost" (
PsExec.exe \\%ServerName% -accepteula CMD /C "CD /D %BatPath% & %BatName%" >>%LOGFILE% 2>&1
)
:: Ending logs
echo ******************************************************************** >>%LOGFILE% 2>&1
echo **** End **************** >>%LOGFILE% 2>&1
echo ******************************************************************** >>%LOGFILE% 2>&1
echo End at %DATE%%TIME% >>%LOGFILE% 2>&1
echo ------------------------------------------------------------ >>%LOGFILE% 2>&1
ENDLOCAL
goto:eof
remoteexecute.bat
最新推荐文章于 2025-03-26 14:38:23 发布