Windows推包脚本

2/13/2017来源:经验技巧人气:1698

关于Windows的推包升级可以用自动化工具,但如果机器数量不多,使用脚本效率更高,这里使用到PsExec.exe工具。

结构:

initServer.bat

work.bat

PsExec.exe

files(要推的文件)

resSuccess.log(执行成功的日志)

resFaild.log(执行失败的日志)

init.bat是把serverPWD.txt 里面目标ip和密码传到work.bat

initServer.bat

echo -----start at:%data% %time%----->resSuccess.log
echo -----start at:%data% %time%----->resFaild.log

for /F “tokens=1,2 delims=:” %%i in(serverPWD.txt)do(call work.bat %%i %%j)

echo -----end at:%data% %time%----->resSuccess.log
echo -----end at:%data% %time%----->resFaild.log

work.bat的作用是把files里的文件拷贝到目标机器上,然后执行上面的脚本

work.bat

set ip=%1%
set pwd=%2%
set files=files

net use \\%ip% “%pwd%” /user:”administrator”

if %errorlevel% EQU 0 (
xcopy /S /E /Y %files% \\%ip%\C$
ping 127.0.0.1 –n 2
start cmd /c PsExec.exe \\%ip% -u administrator –p %pwd% -w C:\client C:\client\run.bat

net use \\%ip%\IPC$ /del
echo %ip%>> resSuccess.log
)else(
echo %ip%>> resFaild.log
)