使用PsExec.exe 文件进行远程批处理文件执行。
使用xcopy进行远程文件拷贝
1:RemoteDeployment_main.bat 修改该文件。 制定目标文件路径。
2:RemoteDeployment_run.bat 设置该文件, 填写需要部署的远程文件的 ip 及登录用户名密码
3: RemoteDeployment 将准备部署的文件放大该目录下。
4:点击执行RemoteDeployment_run.bat 批处理文件。 开始批量部署
RemoteDeployment_main.bat
@echo off
set TargetIP=%1
if "%TargetIP%" == "" (
set TargetIP=
)
set TargetUser=%2
if "%TargetUser%" == "" (
set TargetUser=
)
set TargetPwd=%3
if "%TargetPwd%" == "" (
set TargetPwd=
)
set RemoteFullPath=%4
if {%RemoteFullPath:~-1%}=={\} set RemoteFullPath=%RemoteFullPath:~0,-1%
if {%RemoteFullPath:~-1%}=={/} set RemoteFullPath=%RemoteFullPath:~0,-1%
set RemoteSymbol=%RemoteFullPath:~0,1%
set RemotePath=%RemoteFullPath:~2%
net use * /del /y
net use \\%TargetIP% %TargetPwd% /user:%TargetUser%
xcopy /Y /E RemoteDeployment\RemoteDeployment.bat \\%TargetIP%\%RemoteSymbol%$%RemotePath%\S5500T-simu_linked
::等待文件拷贝完成
set trycount=1
:whilecopy
echo 等待文件拷贝完成-----%trycount%
ping 127.0.0.1 -n 2 >nul
if exist \\%TargetIP%\%RemoteSymbol%$%RemotePath%\S5500T-simu_linked goto endwhilecopy
set /a trycount=%trycount%+1
if "%trycount%"=="10" goto endwhilecopy
goto whilecopy
:endwhilecopy
if not exist \\%TargetIP%\%RemoteSymbol%$%RemotePath%\S5500T-simu_linked (
echo 文件拷贝失败,退出>>Test_TEP.log
goto end
)
echo 文件拷贝成功>>Test_TEP.log
::执行
set trycount=1
:whileexec3
echo 第%trycount%次执行脚本
psexec \\%TargetIP% -u %TargetUser% -p %TargetPwd% -s -d -w %RemoteSymbol%:%RemotePath%\S5500T-simu_linked\ %RemoteSymbol%:%RemotePath%\S5500T-simu_linked\RemoteDeployment.bat
goto endwhileexec3
:endwhileexec3
echo 远程执行成功>>Test_TEP.log
goto end
:enderror
echo invalid parameter!
echo should be: RemoteIP RemoteUser RemotePwd FtpServerIp FtpServerPort FtpServerUser FtpServerPwd RemoteInstallSymbol RemoteInstallPath LocalInstallFilePath
goto end
:end
RemoteDeployment_run.bat
del /F /Q Test_TEP.log
call RemoteDeployment_main.batIP administratorHuawei@123c:\