2

I want a batch file to pull information from the first line of a text file (notepad), use that information to add information to a DNS server, and then delete it. I'm thinking if I create a loop, I can make it go all the way through the text file, using the first line of information to add to the DNS server and then deleting the first line before starting a loop. For example... The batch file would be

@echo off
:start
dnscmd "mydns" /zoneadd (need to know the command from here to add the FQDN from the text file)
::(Need to know the command here to delete the first line of the text file and save the file)
goto start 

The text file reads

Siteno1.com
Siteno2.com
Siteno3.com

So I want it to add Siteno1.com to the dns, then delete it, start at the beginning of the text file, and add Siteno2.com to the dns, delete it, and start from the beginning again until the text file is empty.

1 Answer 1

2

There's no built-in primitive in CMD.EXE to delete lines from text files. I suspect you'd find utility in the for command.

@echo off
for /f %%i in (textfile.txt) do echo dmscmd "mydns" /zoneadd %%i

That will iterate thru all the lines in textfile.txt displaying the example dnscmd command-line for each line of the file. (Obviously, remove the echo to have it actually execute commands).

The syntax for for is somewhat arcane. When you use for at a bare command-prompt you don't double %% the environment variables. I find for to be incredibly handy and use it on a daily basis (but, then, I'm also at the command-prompt on a daily basis, too).

2
  • That was VERY helpful! One more thing I need though, if you can add it to the command above, I need each of the sites being added to the Forward Lookup Zones to have a loopback Host added (done in the GUI by right clicking in the window and selecting New Host (A) and inputting 127.0.0.1 as the IP Address) what I have so far on the CMD is: for /f %i in (MasterTest.txt) do dnscmd 140.21.20.2 /zoneadd %i That adds it to the dns but doesn't input the loopback. :) if you could help me with that I'd be very appreciative. Aug 17, 2011 at 1:50
  • Look at my answer to your other question. Aug 17, 2011 at 1:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .