| Posted: 07-February-2010 at 20:25 | IP Logged
|
|
|
Howdy
Earlier in the year I was working on developing some scripts to add a bit more flexibility on Microsoft's WSUS server at no cost. I've dug up a freeware tool ( WUInstall.exe ,downloadable from http://www.xeox.com/index.php/en/tools/wuinstall/25-wuinstal l-howto ) and put togethere some scripts (available at http://winpatch.sourceforge.net/, not documented yet and still in beta - hope to have more time to finish this project). However, I was suddently (as in past experiences) faced with the problem of distributing configuration changes for latter updates (post initial roll-out).
So I though long and hard about it and I came up with the concept of storing this in DNS. I looked at SRV records and unfortunately this was not a good match (too restricted), so I've suddenly realised that TXT DNS records give me the flexibility that I need.
So my DNS TXT records (winpatch.dsi.net.nz , internal) holds the following information:
SMTPServer,192.168.200.200 SMTPPort,25 TO,myemail@mydomain.com
etc, as many as you need...
So this will ensure that a simple scripted NSlookup can return that information to any of the server querrying DNS...
Next challenge was to actually transfer the constants in batch variables that I can use in the body of the scripts ... so here are a couple of tricks:
1. Reading the variables from DNS and parsing to a local temp file:
::========================================== :: Read parameters from DNS and store them in batch variables ::========================================== nslookup -querytype=TXT winpatch > %systemroot%\winpatch.txt For /f "skip=5 tokens=*" %%j IN (%systemroot%\winpatch.txt) DO call :Setvars %%j ::==========================================
2. The actual serialised process of reading one variable at a time and store it for later use in the script (two parts to this process as bellow):
::========================================== ::Routine to read parameters from local file and store them in batch variables ::========================================== :SetVars set tempset=%1 set tempset=%tempset:"=% For /f "delims=, tokens=1,2" %%j IN ('echo %tempset%') DO call :SetVars2 %%j %%k REM echo %tempset% >> %systemroot%\winpatch.ini goto :END ::==========================================
::========================================== ::Routine to read parameters from DNS and store them in batch variables ::========================================== :SetVars2 set VarName=%1 Set VarVal=%2 set %VarName%=%VarVal% set VarName= Set VarVal= Goto :END ::==========================================
This method can be extended to "cache" the variables in a local file (if DNS is unavailable for some reason - see the REM-out line - and of course, with a bit of script logic change eg: use local if DNS errors). It is also based on a process of DO ... UNTIL EOF, so you can store as many variables in this format: VARIABLENAME,VARIABLEVALUE
So no more batch pushing .txt, cfg or .ini files to your scripts - that is ...if you ever used them. And no more poking holes in the firewall to allow file copy to your DMZ machines ...
Until next time ...
DSI-Tech
|