[背景]公司最近上了百餘台伺服器,為了給cacti監控而開啟了snmp,要更改snmp的共同體和可以接受來自那些機子的snmp包.如果手工加的話,效率可想而知.所以就想到了用指令碼wmi(snmp.vbs),但是在用p***ec遠端執行這個指令碼也是很慢,因為它們是順序性的,所以處理效率還是慢.所以,想到了批處理的併發(pro.bat和p***ec.bat),這樣不是更好嘛!
[過程]
snmp.vbs
const hkey_local_machine = &h80000002
strcomputer = "."
ip1="x.x.x.x"
ip2="x.x.x.x"
comm="***x"
set objregistry=getobject("winmgmts://"&strcomputer&"/root/default:stdregprov")
strkeypath = "system\currentcontrolset\services\snmp\parameters\permittedmanagers"
strvaluename = "1"
objregistry.delet.ue hkey_local_machine, strkeypath, strvaluename
dwvalue1=ip1
objregistry.setstrin**alue hkey_local_machine, strkeypath, strvaluename, dwvalue1
dwvalue2=ip2
strvaluename1 = "2"
objregistry.setstrin**alue hkey_local_machine, strkeypath, strvaluename1, dwvalue2
strkeypath1 = "system\currentcontrolset\services\snmp\parameters\validcommunities"
strvaluename = "public"
objregistry.delet.ue hkey_local_machine, strkeypath1, strvaluename
dwvalue3="4"
strvaluename1 = comm
objregistry.setdwordvalue hkey_local_machine, strkeypath1, strvaluename1, dwvalue3
set objwmiservice = getobject("winmgmts:" _
& "!\\" & strcomputer & "\root\cimv2")
set colservicelist = objwmiservice.execquery _
("select * from win32_service where name='snmp'")
for each objservice in colservicelist
errreturn = objservice.startservice()
next
w..sleep 20000
set colservicelist = objwmiservice.execquery("associators of " _
& " where " _
& "assocclass=win32_dependentservice " & "role=dependent" )
for each objservice in colservicelist
objservice.startservice()
next
pro.bat
for /l %%i in (1,1,254) do (start /min cmd /c p***ec.bat x.x.x.%%i)
p***ec.bat
p***ec
\\%1 -u admin -p pass cmd /c c:/snmp.vbs
if %errorlevel%==0 (echo %1 ok>>log.txt) else (echo %1 fail>>log.txt)
[結果]
這樣在客戶端只要執行pro.bat,在客戶端就會開啟254個cmd埠,就像個多程序樣去執行snmp.vbs.至於結果可以看log.txt檔案.
Windows環境下「路徑」處理
windows環境下 路徑 處理 標頭檔案 include 引用庫檔案 pragma comment lib,shlwapi.lib 路徑截斷與合併函式 pathremoveargs 去除路徑後面的引數 pathremovebackslash 去除路徑最後的反斜槓 pathaddbackslash ...
windows下apache併發配置
apache優化步驟 1 先檢視apache的執行模式,檢視命令 httpd l 這裡可以看到執行模式是 winnt 模式。2 修改apache 的httpd mpm.conf 配置 開啟 apache2 conf extra httpd mpm.conf 每個機器可能httpd mpm.conf ...
CVS使用 windows環境下
經驗 1,wincvs中執行checkout動作的單位是 module 即匯入cvs倉庫的專案名稱。import時有設定,要記好。2,cvsroot pserver username password localhost 倉庫名 3,初始化乙個cvs倉庫,並將乙個現有專案匯入到cvs中 1 通過cv...