+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Batch file help - DNS import - WHAT do you WANT from me stupid batch file? in Coding and Web Development; Hi all. Today's gripe is this one. Written a batch file to bulk import some A records into DNS (200-odd) ...
  1. #1

    Miscbrah's Avatar
    Join Date
    Dec 2011
    Posts
    868
    Thank Post
    241
    Thanked 240 Times in 144 Posts
    Rep Power
    112

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

    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:

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

    Code:
    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?

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    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
    Last edited by Steve21; 28th May 2012 at 11:42 AM.

  3. Thanks to Steve21 from:

    Miscbrah (28th May 2012)

  4. #3

    Miscbrah's Avatar
    Join Date
    Dec 2011
    Posts
    868
    Thank Post
    241
    Thanked 240 Times in 144 Posts
    Rep Power
    112
    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

    Code:
    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?
    Last edited by Miscbrah; 28th May 2012 at 12:12 PM.

  5. #4

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by Miscbrah View Post
    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

  6. #5

    Miscbrah's Avatar
    Join Date
    Dec 2011
    Posts
    868
    Thank Post
    241
    Thanked 240 Times in 144 Posts
    Rep Power
    112
    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:

    Code:
    dnscmd lhsdc1 /RecordAdd domain.name.sch.uk acer-test /Aging /OpenAcl A 10.108.10.167
    
    Pause
    But the following doesn't:

    Code:
    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

  7. #6

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by Miscbrah View Post
    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:

    Code:
    dnscmd lhsdc1 /RecordAdd domain.name.sch.uk acer-test /Aging /OpenAcl A 10.108.10.167
    
    Pause
    But the following doesn't:

    Code:
    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

  8. #7

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by Miscbrah View Post
    Just clueless
    Remove the " around your file name.

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

    etc

    Steve

  9. Thanks to Steve21 from:

    Miscbrah (28th May 2012)

  10. #8

    Michael's Avatar
    Join Date
    Dec 2005
    Location
    Birmingham
    Posts
    9,241
    Thank Post
    239
    Thanked 1,567 Times in 1,249 Posts
    Rep Power
    339
    Why are you having to do this? Can't you create a Secondary or Stub DNS Zone?

  11. Thanks to Michael from:

    Miscbrah (28th May 2012)

  12. #9

    Miscbrah's Avatar
    Join Date
    Dec 2011
    Posts
    868
    Thank Post
    241
    Thanked 240 Times in 144 Posts
    Rep Power
    112
    Quote Originally Posted by Steve21 View Post
    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!
    Last edited by Miscbrah; 28th May 2012 at 02:08 PM.

SHARE:
+ Post New Thread

Similar Threads

  1. RBCs: What do you want from them?
    By sparkeh in forum Internet Related/Filtering/Firewall
    Replies: 17
    Last Post: 24th November 2010, 07:57 PM
  2. What do you want from your MIS system
    By johnhunsley in forum MIS Systems
    Replies: 22
    Last Post: 22nd November 2010, 09:29 AM
  3. Replies: 51
    Last Post: 10th November 2009, 05:23 AM
  4. [Pics] Is There Such A Thing? If There Is What Do You Want Me To Do About It?
    By DaveP in forum Jokes/Interweb Things
    Replies: 0
    Last Post: 21st September 2008, 10:15 AM
  5. What do you exclude from antivirus scans?
    By zag in forum How do you do....it?
    Replies: 7
    Last Post: 8th February 2008, 07:09 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •