DSI NETWORKS & SOLUTIONS
  Home     Forum  
Register   Login  
   Forum:
  Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
Advanced Tech Topics
 Forum-Advanced Tech Topics
Subject Topic: CMD batch script store settings in DNS Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
DSI-Tech
Admin Group
Admin Group


Joined: 25-January-2003
Posts: 38

Online Status: Offline
Posted: 07-February-2010 at 20:25 | IP Logged Quote DSI-Tech

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

Back to Top View DSI-Tech's Profile Search for other posts by DSI-Tech
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.92
Copyright ©2001-2004 Web Wiz Guide
* Webmaster |  ©1999-2009 DSI NETWORKS & SOLUTIONS |  Site Launched: 21 Oct 2004
Powered By EzASPSite v2.0 RC3a