MRTG使用了一段时间,偷懒写了个bat,MRTG安装在了C:\MRTG,安装了perl语言,www目录为C:\inetpub\wwwroot\MRTG\,可以用以下批处理文件执行交互式安装,自动化添加服务,自动化添加注册表,只需要在添加完毕后手动启动服务即可。
需要用管理员权限运行!!!
批处理代码如下
set "mrtg_path=C:\mrtg"
set /p host="Enter host IP: "
set /p hostname="Enter hostname:"
set /p community="Enter community: "
set service_name=%hostname%
set reg_key=%hostname%
mkdir C:\inetpub\wwwroot\MRTG\%hostname%\
echo make a new configfile for %hostname% > C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.cfg
perl C:\mrtg\bin\cfgmaker %community%@%host%:::::2 --global "WorkDir: C:\inetpub\wwwroot\MRTG\%hostname%" --ifref=ip,eth --ifdesc=descr --global "options[_]: growright,bits" --output C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.cfg
echo runasDaemon:yes>>C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.cfg
echo interval:5>>C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.cfg
echo language:chinese>>C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.cfg
echo Creating %hostname% webpage...
perl C:\mrtg\bin\indexmaker C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.cfg>C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.html
echo Creating %hostname% webpage done
echo Creating %hostname% service...
C:\mrtg\bin\instsrv %hostname% c:\mrtg\bin\srvany.exe
echo Creating %hostname% service done
echo Writing %hostname% registry key...
echo make a new registry for %hostname% > C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.reg
echo Windows Registry Editor Version 5.00 > C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\%hostname%\Parameters] >> C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.reg
echo "Application"="c:\\perl64\\bin\\wperl.exe" >> C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.reg
echo "AppParameters"="c:\\mrtg\\bin\\mrtg --logging=C:\\inetpub\\wwwroot\\MRTG\\%hostname%\\%hostname%.log C:\\inetpub\\wwwroot\\MRTG\\%hostname%\\%hostname%.cfg" >> C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.reg
echo "AppDirectory"="c:\\mrtg\\bin\\" >> C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.reg
regedit /s "C:\inetpub\wwwroot\MRTG\%hostname%\%hostname%.reg"
pause