Miscbrah Posted May 28, 2012 Posted May 28, 2012 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?
Steve21 Posted May 28, 2012 Posted May 28, 2012 (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 May 28, 2012 by Steve21 1
Miscbrah Posted May 28, 2012 Author Posted May 28, 2012 (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 May 28, 2012 by Miscbrah
Steve21 Posted May 28, 2012 Posted May 28, 2012 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
Miscbrah Posted May 28, 2012 Author Posted May 28, 2012 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
Steve21 Posted May 28, 2012 Posted May 28, 2012 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
Steve21 Posted May 28, 2012 Posted May 28, 2012 Just clueless Remove the " around your file name. for /F "tokens=1,2 delims=," %%1 in (ahosts.txt) ... etc Steve 1
Michael Posted May 28, 2012 Posted May 28, 2012 Why are you having to do this? Can't you create a Secondary or Stub DNS Zone? 1
Miscbrah Posted May 28, 2012 Author Posted May 28, 2012 (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! Edited May 28, 2012 by Miscbrah
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now