windows server 2012 批量执行BAT安装脚本的简单实现

运用此脚本测试安装ZABBIX

将执行的脚本和安装文件等全部拷贝到管理机器的如下路径:

C:\tmps\Zabbix_Agent

目录结构

 

C:\tmps\Zabbix_Agent\cmdexec.bat  文件内容如下:

FOR /F "delims=, tokens=1,2,3" %%i in (C:\tmps\Zabbix_Agent\pwd.txt) do C:\tmps\Zabbix_Agent\bat.bat %%i %%j %%k

 

C:\tmps\Zabbix_Agent\bat.bat  文件内容如下:

@set ip=%1
@set uname=%2
@set upwd=%3
wmic /node:%ip% /user:%uname% /password:%upwd% os >nul || goto :sb
dir z:\ >nul 2>&1 && goto :vsb
wmic /node:%ip% /user:%uname% /password:%upwd% process call create "cmd /c mkdir c:\Zabbix_Agent" || goto :sb
wmic /node:%ip% /user:%uname% /password:%upwd% process call create "cmd /c mkdir c:\Zabbix_Agent\bin" || goto :sb
net use z: \\%ip%\c$\Zabbix_Agent %upwd% /user:%uname%
ping -n 3 127.0.0.1>nul
copy C:\tmps\Zabbix_Agent\bin z:\bin
copy C:\tmps\Zabbix_Agent\install.bat z:\
ping -n 5 127.0.0.1>nul
schtasks /Create /S %ip% /U %uname% /P %upwd% /TN taskName /TR c:\Zabbix_Agent\install.bat /SC once /ST 00:00 || goto :delshare
schtasks /Run /S %ip% /U %uname% /P %upwd% /TN taskName || goto :delshare
ping -n 5 127.0.0.1>nul
@set slptimes=1
goto :delshare


:delshare
net use z: /delete
ping -n 5 127.0.0.1>nul
schtasks /Delete /S %ip% /U %uname% /P %upwd% /TN taskName /f
goto :eof

:sb
@echo =================================== Can't connect to %ip%===================================
ping -n 5 127.0.0.1>nul
goto :eof

:vsb
@echo =================================== Can't use v:\ %vnode%===================================
goto :eof

:eof

 

C:\tmps\Zabbix_Agent\install.bat  文件内容如下:

@ echo off
%1 %2
ver|find "5.">nul&&goto :Admin
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :Admin","","runas",1)(window.close)&goto :eof
:Admin
echo Server=192.168.1.1>> c:\Zabbix_Agent\zabbix_agentd.conf    
echo ServerActive=192.168.1.1 >> c:\Zabbix_Agent\zabbix_agentd.conf    
echo Hostname=%COMPUTERNAME% >> c:\Zabbix_Agent\zabbix_agentd.conf
echo StartAgents=5 >> c:\Zabbix_Agent\zabbix_agentd.conf
echo DebugLevel=3 >> c:\Zabbix_Agent\zabbix_agentd.conf
echo LogFile=c:\Zabbix_Agent\zabbix_agentd.log >> c:\Zabbix_Agent\zabbix_agentd.conf
echo Timeout=3 >> c:\Zabbix_Agent\zabbix_agentd.conf
echo HostMetadata=windows >> c:\Zabbix_Agent\zabbix_agentd.conf
echo installing service
cd c:\Zabbix_Agent\bin
zabbix_agentd.exe -i -c c:\Zabbix_Agent\zabbix_agentd.conf 
zabbix_agentd.exe -s -c C:\Zabbix_Agent\zabbix_agentd.conf
::zabbix_agentd.exe -d -c C:\Zabbix_Agent\conf\zabbix_agentd.conf
net stop "Zabbix Agent"
net start "Zabbix Agent" 

 

C:\tmps\Zabbix_Agent\pwd.txt 文件内容如下:

ip,username,password

多台机器写多行

 

执行C:\tmps\Zabbix_Agent\cmdexec.bat  即可完成批量安装

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页