Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Batch file help - DNS import - WHAT do you WANT from me stupid batch file?


Recommended Posts

Posted

Hi all.

 

Today's gripe is this one. Written a batch file to bulk import some A records into DNS (200-odd) and seem to be falling at the first line:

 

for /f "tokens=1,2 delims=," %1 in ("ahosts.txt") do

 

Which returns:

 

in was unexpected at this time

 

It should be very much expected, right?? I opened the command window from the same folder the batch file and hosts .txt is in and ran the batch file, the delimiter is set right...

 

...Why is it picking on me? :(

Posted (edited)

Isn't it double %%?

 

- Edit : Just double checked and that seems to be the issue :)

 

(Single %)

C:\test>test.bat

in was unexpected at this time.

C:\test>for /f "tokens=1,2 delims=," in ("ahosts.txt") do echo %1

C:\test>test.bat

 

(Double %%)

C:\test>for /F "tokens=1,2 delims=," %1 in ("ahosts.txt") do echo %1

C:\test>echo ahosts.txt

 

Steve

Edited by Steve21
  • Thanks 1
Posted (edited)

Thanks Steve! Ok, that's something new but it's still not working. Not sure what the reason is.

 

My csv file looks like this:

 

computer1,10.108.1.1

computer2,10.108.1.2

computer3,10.108.1.3

 

And my batch file now says exactly (well, domain name's right:)

 

for /F "tokens=1,2 delims=," %%1 in ("ahosts.txt") do dnscmd lhsdc1 /RecordAdd domain.name.sch.uk %1 /Aging /OpenAcl A %2

pause

 

But gives me ERROR_INVALID_PARAMETER; 87 (0x57) the parameter is incorrect when run.

 

I'm so stumped now - any ideas?

Edited by Miscbrah
Posted
But gives me ERROR_INVALID_PARAMETER; 87 (0x57) the parameter is incorrect when run.

 

I'm so stumped now - any ideas?

 

That's an error with your dnscmd parameters, not the bat file as such :)

 

What's [/Aging] [/OpenAcl] supposed to be?

 

Not sure dnscmd before, but is that valid command? Seems odd thing to be using especially in square brackets etc

 

Steve

Posted

Cheers Steve - no never used it myself before today.

 

Tested it out and tweaked it a little and it runs perfectly for one entry at a time if I put in the name and IP add myself, but stubbornly refuses to call that batch file! As in, the following works and adds the A record:

 

dnscmd lhsdc1 /RecordAdd domain.name.sch.uk acer-test /Aging /OpenAcl A 10.108.10.167

Pause

 

But the following doesn't:

 

for /F "tokens=1,2 delims=," %%1 in ("ahosts.txt") do dnscmd lhsdc1 /RecordAdd domain.name.sch.uk %%1 /Aging /OpenAcl A %%2

pause

 

Just clueless :(

Posted
Cheers Steve - no never used it myself before today.

 

Tested it out and tweaked it a little and it runs perfectly for one entry at a time if I put in the name and IP add myself, but stubbornly refuses to call that batch file! As in, the following works and adds the A record:

 

dnscmd lhsdc1 /RecordAdd domain.name.sch.uk acer-test /Aging /OpenAcl A 10.108.10.167

Pause

 

But the following doesn't:

 

for /F "tokens=1,2 delims=," %%1 in ("ahosts.txt") do dnscmd lhsdc1 /RecordAdd domain.name.sch.uk %%1 /Aging /OpenAcl A %%2

pause

 

Just clueless :(

 

I think your code isn't getting what you want in the first place. Thus it's breaking on the command. You're not running IP currently from your original BAT file.

 

Steve

Posted (edited)
Remove the " around your file name.

 

for /F "tokens=1,2 delims=," %%1 in (ahosts.txt) ...

 

etc

 

Steve

 

 

Nailed it! Cheers :)

 

Thanks Michael - wanted the records in the same zone which is already partially populated. Would have made a secondary zone, waited for that to populate then changed it to primary nearer 'domain move time' if not...

 

...Unless you've spotted a better way of doing things from amongst my querying today...

 

EDIT - and how on earth did you become a donator? I tried HARD to find a link for donations and failed at that too! :o

Edited by Miscbrah

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...