[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 558
  • Last Modified:

grabbing a subtring in a batch file

I am trying to automate DNS zone creation by using a batch file fired through one of Plesk's events.  

Using the dnscmd command, the batch checks to see if the zone exists.  If the zone does not exist, the script adds it according to specs.  If it does exist, and it is a secondary zone, the script deletes and recreates it according to specs.  If it exists, and it is a primary zone, the script leaves it alone.  That part is all working.  

Since we have some custom configurations, I also wanted to verify that if the zone is a secondary zone, it was also using the target server as the master.  If it is using a different master, leave it alone.  While I was able to retrieve the list of master servers, I was unable to match the text because of an odd problem with the output.  Windows uses 0x0d,0x0a as the end-of-line marker, and the batch environment recognizes this.  On this particular line of output, however, the end-of-line includes an additional 0x0d; the EOL is marked as 0x0d,0x0d,0x0a.  

The problem section is after the :check3 label.  I was receiving some weird feedback from the FOR /F loop, and added the echo commands to help debug.  I eventually loaded the output of dnscmd directly into a hex editor to have a look.  Using the algorithm shown in the script below, my test variables %%A and %%B retain the additional 0x0d, thus messing up my comparisons.  The other lines I check from dnscmd do not show this issue - it is only with the output related to the MasterServers information.  How can I resolve this?

The requirements: batch functionality *only*...we know we can recode this as VBScript and instantly resolve the issue, but that is not our goal here.  The solution must not involve any other applications to parse the output from dnscmd.

@echo off
rem 1.2.3.4 = target server holding Plesk domains
rem 5.6.7.8 = our public nameservers

rem *** USER CONFIGURED VARIABLES
set dnsupdlog=test.log
set dnsupdip=1.2.3.4

rem *** other script variables (DO NOT MODIFY)
rem the next line is "set tab=<tab>%"
set tab=	%
set nozone=%1

rem *** make sure a domain was provided
if "%1"=="" set nozone=**NO ZONE PROVIDED**
for /F "delims=" %%A IN ('date /T') DO SET dnsupdtime=%%A
echo --------%dnsupdtime% begin zone %nozone% > %dnsupdlog%
if "%nozone%"=="**NO ZONE PROVIDED**" (
  echo You must provide a domain name, e.g., test.bat mydomain.com >> %dnsupdlog%
  goto :endit
)

rem *** does domain exist yet?  if not, just add the domain
"%plesk_bin%\dnscmd.exe" 5.6.7.8 /zoneinfo %1 | find "query failed" > NUL
if ERRORLEVEL 1 (
  echo Zone exists ... continue checking >> %dnsupdlog%
  goto :check2
)
echo Zone does not exist ... add domains >> %dnsupdlog%
goto :add_domains

:check2
rem *** domain already exists.  Is it primary?  if yes, skip
for /F "tokens=1-2 skip=1 delims=%tab%: " %%A IN ('"%plesk_bin%\dnscmd.exe" 5.6.7.8 /zoneinfo %1 Type') DO (
  if "%%A"=="Dword" (if "%%B"=="1" (
    echo Domain is a primary zone.  No work to be done. >> %dnsupdlog%
    goto :endit
    )
    echo Not a primary zone ... continue checking >> %dnsupdlog%
    goto :check3
  )
)
echo ***ERROR*** Could not determine zone type!! >> %dnsupdlog%
goto :endit

:check3
rem *** secondary domain exists.  Is it using this as master?  if not, skip
set isfound=no
for /F "skip=1 tokens=2-3 delims=%tab%=> " %%A IN ('"%plesk_bin%\dnscmd.exe" 5.6.7.8 /zoneinfo %1 MasterServers') DO (
  echo %%A
  echo %%B
  echo %%A,
  echo %%B,
  if /i "%%A"=="count" (if /i "%%B" NEQ "1" (
    echo Received unexpected master server count %%B!! >> %dnsupdlog%
    goto :endit
    )
  )
  if /i "%%A"=="Addr[0]" (
    if /i "%%B" NEQ "%dnsupdip%" (
      echo Different master server %%B.  No work to be done. >> %dnsupdlog%
      goto :endit
      )
    set isfound=yes
  )
)
if /i "%isfound%" NEQ "yes" (
  echo Did not find expected IP %dnsupdip% as master server.  No work to be done. >> %dnsupdlog%
  goto :endit
)

:del_domains
rem *** delete domains here
echo del >> %dnsupdlog%

:add_domains
rem *** add domains here
echo add >> %dnsupdlog%

:endit
echo --------%dnsupdtime% end zone %nozone% >> %dnsupdlog%
set isfound=
set nozone=
set dnsupdtime=
set dnsupdlog=
set dnsupdip=

Open in new window

0
Steve Bink
Asked:
Steve Bink
  • 12
  • 10
  • 3
1 Solution
 
Steve KnightIT ConsultancyCommented:
Can you upload one of the dodgy outputs from dnscmd into a file and attach please?

Haven't tried it with a file with multiple CR off hand but thinking it may be worth piping dnscmd output through find or more using ^| in the FOR command.

for find that would be something along the lines of ^| find /v "something not to find"

Steve
0
 
Steve BinkAuthor Commented:
Sure thing.  I edited this file to anonymize the domain name and IPs, but it is otherwise intact.  dnscmd.exe is a Microsoft tool, so you should be able to reproduce this fairly easily by querying any DNS server.

The attached file is the whole output (dnscmd 5.6.7.8 /zoneinfo oneofourdomains.com).  Adding the "MasterServers" parameter to the end limits the output to the "Zone Masters" section, but is otherwise identical.
dns.txt
0
 
Steve KnightIT ConsultancyCommented:
I have got hold of DNScmd.exe from one of my servers but don't have a DNS server I can run this against until I am in the office.

Running from your test file though I can only get the :check3 for command to work when using an "=" as a delimeter together with the previously inserted tab when the line is re-ordered to:

for /F "skip=1 tokens=2-3 delims==> %tab%"

I'll take a look when back in the office later with local DNS to query

Steve
0
 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

 
Steve BinkAuthor Commented:
The ">" delimiter was another troubleshooting effort and is not needed.  The actual delimiters should be <space>, <tab>, and '='.  Thanks for your assist.
0
 
Steve KnightIT ConsultancyCommented:
Sorry I can't test any more at the moment.... piping your test file through more certainly shows the rights results.  No doubt someone else will be along soon anyway :-)  Otherwise will check later.
0
 
Bill PrewCommented:
As Steve mentioned piping through MORE should help.  Have you tried something like this?  I don't think you need the %TAB% with MORE, I think it will expand those to spaces.

for /F "skip=1 tokens=2-3 delims== " %%A IN ('"%plesk_bin%\dnscmd.exe" 5.6.7.8 /zoneinfo %1 MasterServers^|more') DO (

~bp
0
 
Steve BinkAuthor Commented:
I tried with more, but the resulting output still had the additional 0x0d on these lines.  It *looks* fine, but a hex editor makes the problem readily apparent, and the batch file will still miss the comparison.
0
 
Bill PrewCommented:
That is odd on MORE, take a look at the hex output of the two files below.  I created a DNS.TXT from your post with the "extra" 0x0D characters in it.  Then I did the following command:

MORE <DNS.TXT >DNS2.TXT

Notice on my Windows XP system MORE seems to do the trick.

~bp
================ DNS.TXT ===================
 
Zone query result:^Zone info:^^ptr                   = 0021E9B8^^zone 
5666277677276776730566626666300777222222222222222222232333343430076662
AFE501552902535C4AAAFE509E6FAA90420000000000000000000D000215928A9AFE50
 
name             = oneofourdomains.com^^zone type             = 2^^upd
6666222222222222232666666776666667266600766627776222222222222232300776
E1D50000000000000D0FE5F6F524FD19E3E3FDA9AFE5049050000000000000D02A9504
 
ate                = 0^^DS integrated         = 0^^data file          
6762222222222222222323004526676676766222222222323006676266662222222222
1450000000000000000D00A94309E45721454000000000D00A94141069C50000000000
 
   = oneofourdomains.com.dns^^using WINS            = 0^^using Nbstat 
2223266666677666666726662667007766625445222222222222323007766624677672
000D0FE5F6F524FD19E3E3FDE4E3A9539E7079E3000000000000D00A9539E70E234140
 
         = 0^^aging                 = 0^^  refresh interval    = 0^^  
2222222223230066666222222222222222223230022766767626676776622223230022
000000000D00A9179E700000000000000000D00A900256253809E45261C0000D00A900
 
no refresh          = 0^^  scavenge available  = 0^^Zone Masters^ Addr
6627667676222222222232300227667666626766666662232300566624677677024667
EF025625380000000000D00A90033165E7501619C12C500D00A9AFE50D134523A01442
 
 Count = 1^^^^Master[0] => 1.2.3.4^^^Zone Secondaries^^NULL IP Array.^
2467672323000046776753523323232323000566625666666766700454424524776720
03F5E40D01DA99D13452B0D0DE01E2E3E4DA9AFE50353FE412953A9E5CC090012219ED
 
^^secure secs           = 3^^last successful xfr   = not since restart
0076677627667222222222223230066772776667767627672223266727666627677677
A93535250353300000000000D03A9C1340353353365C0862000D0EF4039E3502534124
 
 (0)^^last SOA check        = not since restart (0)^Command completed 
2232006677254426666622222222326672766662767767722320466666626667667662
0809A9C13403F103853B00000000D0EF4039E35025341240809A3FDD1E403FD0C54540
 
successfully.^
77666776766720
353353365CC9EA
 
================ DNS2.TXT ===================
 
Zone query result:^^Zone info:^^        ptr                   = 0021E9
5666277677276776730056662666630022222222777222222222222222222232333343
AFE501552902535C4ADAAFE509E6FADA000000000420000000000000000000D0002159
 
B8^^        zone name             = oneofourdomains.com^^        zone 
4300222222227666266662222222222222326666667766666672666002222222276662
28DA00000000AFE50E1D50000000000000D0FE5F6F524FD19E3E3FDDA00000000AFE50
 
type             = 2^^        update                = 0^^        DS in
7776222222222222232300222222227766762222222222222222323002222222245266
49050000000000000D02DA000000005041450000000000000000D00DA000000004309E
 
tegrated         = 0^^        data file             = oneofourdomains.
7667676622222222232300222222226676266662222222222222326666667766666672
45721454000000000D00DA000000004141069C50000000000000D0FE5F6F524FD19E3E
 
com.dns^^        using WINS            = 0^^        using Nbstat      
6662667002222222277666254452222222222223230022222222776662467767222222
3FDE4E3DA00000000539E7079E3000000000000D00DA00000000539E70E23414000000
 
    = 0^^        aging                 = 0^^          refresh interval
2222323002222222266666222222222222222223230022222222227667676266767766
0000D00DA00000000179E700000000000000000D00DA0000000000256253809E45261C
 
    = 0^^          no refresh          = 0^^          scavenge availab
2222323002222222222662766767622222222223230022222222227667666626766666
0000D00DA0000000000EF025625380000000000D00DA000000000033165E7501619C12
 
le  = 0^^        Zone Masters^^ Addr Count = 1^^                Master
6622323002222222256662467767700246672467672323002222222222222222467767
C500D00DA00000000AFE50D134523DA0144203F5E40D01DA0000000000000000D13452
 
[0] => 1.2.3.4^^        Zone Secondaries^^        NULL IP Array.^^    
5352332323232300222222225666256666667667002222222245442452477672002222
B0D0DE01E2E3E4DA00000000AFE50353FE412953DA00000000E5CC090012219EDA0000
 
    secure secs           = 3^^        last successful xfr   = not sin
2222766776276672222222222232300222222226677277666776762767222326672766
00003535250353300000000000D03DA00000000C1340353353365C0862000D0EF4039E
 
ce restart (0)^^        last SOA check        = not since restart (0)^
6627677677223200222222226677254426666622222222326672766662767767722320
35025341240809DA00000000C13403F103853B00000000D0EF4039E35025341240809D
 
^Command completed successfully.^^
0466666626667667662776667767667200
A3FDD1E403FD0C54540353353365CC9EDA

Open in new window

0
 
Steve BinkAuthor Commented:
It looks like your original DNS.TXT did not include the extra 0x0d..

>>> ================ DNS.TXT ===================
[ ... ]
>>>  Count = 1^^^^Master[0] => 1.2.3.4^^^Zone Secondaries^^NULL IP Array.^
>>> 2467672323000046776753523323232323000566625666666766700454424524776720
>>> 03F5E40D01DA99D13452B0D0DE01E2E3E4DA9AFE50353FE412953A9E5CC090012219ED

Maybe it just didn't come through in the download, or your editor 'fixed it for you' when you edited the file.  When I tried:

dnscmd 5.6.7.8 /zoneinfo oneofourdomains.com | more

The resulting output shows the odd EOL.
0
 
Bill PrewCommented:
It must be an issue with the EE upload / download.  When I save your DNS.TXT, it seems to have just 0x0A as EOL, except for a couple of lines that have 0x0D 0x0A at the end.

Attached is a dump of the file right from a save, no manipulation.

~bp
00000000  5A 6F 6E 65  20 71 75 65  72 79 20 72  65 73 75 6C  Zone query resul
00000010  74 3A 0A 5A  6F 6E 65 20  69 6E 66 6F  3A 0A 09 70  t:ÙZone info:ÙËp
00000020  74 72 20 20  20 20 20 20  20 20 20 20  20 20 20 20  tr
00000030  20 20 20 20  20 3D 20 30  30 32 31 45  39 42 38 0A       = 0021E9B8Ù
00000040  09 7A 6F 6E  65 20 6E 61  6D 65 20 20  20 20 20 20  Ëzone name
00000050  20 20 20 20  20 20 20 3D  20 6F 6E 65  6F 66 6F 75         = oneofou
00000060  72 64 6F 6D  61 69 6E 73  2E 63 6F 6D  0A 09 7A 6F  rdomains.comÙËzo
00000070  6E 65 20 74  79 70 65 20  20 20 20 20  20 20 20 20  ne type
00000080  20 20 20 20  3D 20 32 0A  09 75 70 64  61 74 65 20      = 2ÙËupdate
00000090  20 20 20 20  20 20 20 20  20 20 20 20  20 20 20 3D                 =
000000A0  20 30 0A 09  44 53 20 69  6E 74 65 67  72 61 74 65   0ÙËDS integrate
000000B0  64 20 20 20  20 20 20 20  20 20 3D 20  30 0A 09 64  d         = 0ÙËd
000000C0  61 74 61 20  66 69 6C 65  20 20 20 20  20 20 20 20  ata file
000000D0  20 20 20 20  20 3D 20 6F  6E 65 6F 66  6F 75 72 64       = oneofourd
000000E0  6F 6D 61 69  6E 73 2E 63  6F 6D 2E 64  6E 73 0A 09  omains.com.dnsÙË
000000F0  75 73 69 6E  67 20 57 49  4E 53 20 20  20 20 20 20  using WINS
00000100  20 20 20 20  20 20 3D 20  30 0A 09 75  73 69 6E 67        = 0ÙËusing
00000110  20 4E 62 73  74 61 74 20  20 20 20 20  20 20 20 20   Nbstat
00000120  20 3D 20 30  0A 09 61 67  69 6E 67 20  20 20 20 20   = 0ÙËaging
00000130  20 20 20 20  20 20 20 20  20 20 20 20  3D 20 30 0A              = 0Ù
00000140  09 20 20 72  65 66 72 65  73 68 20 69  6E 74 65 72  Ë  refresh inter
00000150  76 61 6C 20  20 20 20 3D  20 30 0A 09  20 20 6E 6F  val    = 0ÙË  no
00000160  20 72 65 66  72 65 73 68  20 20 20 20  20 20 20 20   refresh
00000170  20 20 3D 20  30 0A 09 20  20 73 63 61  76 65 6E 67    = 0ÙË  scaveng
00000180  65 20 61 76  61 69 6C 61  62 6C 65 20  20 3D 20 30  e available  = 0
00000190  0A 09 5A 6F  6E 65 20 4D  61 73 74 65  72 73 0A 20  ÙËZone MastersÙ
000001A0  41 64 64 72  20 43 6F 75  6E 74 20 3D  20 31 0D 0A  Addr Count = 1jÙ
000001B0  09 09 4D 61  73 74 65 72  5B 30 5D 20  3D 3E 20 31  ËËMaster[0] => 1
000001C0  2E 32 2E 33  2E 34 0D 0A  09 5A 6F 6E  65 20 53 65  .2.3.4jÙËZone Se
000001D0  63 6F 6E 64  61 72 69 65  73 0A 09 4E  55 4C 4C 20  condariesÙËNULL
000001E0  49 50 20 41  72 72 61 79  2E 0D 0A 09  73 65 63 75  IP Array.jÙËsecu
000001F0  72 65 20 73  65 63 73 20  20 20 20 20  20 20 20 20  re secs
00000200  20 20 3D 20  33 0A 09 6C  61 73 74 20  73 75 63 63    = 3ÙËlast succ
00000210  65 73 73 66  75 6C 20 78  66 72 20 20  20 3D 20 6E  essful xfr   = n
00000220  6F 74 20 73  69 6E 63 65  20 72 65 73  74 61 72 74  ot since restart
00000230  20 28 30 29  0A 09 6C 61  73 74 20 53  4F 41 20 63   (0)ÙËlast SOA c
00000240  68 65 63 6B  20 20 20 20  20 20 20 20  3D 20 6E 6F  heck        = no
00000250  74 20 73 69  6E 63 65 20  72 65 73 74  61 72 74 20  t since restart
00000260  28 30 29 0A  43 6F 6D 6D  61 6E 64 20  63 6F 6D 70  (0)ÙCommand comp
00000270  6C 65 74 65  64 20 73 75  63 63 65 73  73 66 75 6C  leted successful
00000280  6C 79 2E 0A                                         ly.Ù

Open in new window

0
 
Steve BinkAuthor Commented:
Must be going through a Unix system somewhere along the way.  Have you tried getting some raw output from dnscmd?
0
 
Steve KnightIT ConsultancyCommented:
Looking again yes the dns.txt uploaded is as Bill says only a fw CR / 0D in there, mainly just 0A LF's,

May be worth producing an output and uploading as a non-text, e.g. ZIP it or rename it to a binary file such as .JPG and upload say so it doesn't "adjust" it.

I couldn't get dnscmd.exe to work against the (test) DNS servers to give this output, I am surprised that MORE, MORE /M or FIND "gibberish" /V doesn't filter it out though.

The next alternative may be just to amend the comparison lines so it checks just the right characetrs, or use a FIND in the FOR command to filter only the line that you DO want anyway.

Steve
Add this somewhere above this in your batch (normally at the top)

SETLOCAL ENABLEDELAYEDEXPANSION

And then you could check the specific parts of the lines you want, e.g.:

for /F "skip=1 tokens=2-3 delims=%tab% " %%A IN ('"%plesk_bin%\dnscmd.exe" 5.6.7.8 /zoneinfo %1 MasterServers') DO ( 
  set A=%%A
  set B=%%B 
  if /i "!A:~0,5!"=="count" (if /i "!B:~0,1!" NEQ "1" ( 
    echo Received unexpected master server count %%B!! >> %dnsupdlog% 
    goto :endit 
    ) 
  ) 
  if /i "!A:~0,7!"=="Addr[0]" ( 
    if /i "!B:0,8!" NEQ "%dnsupdip%" ( 
      echo Different master server %%B.  No work to be done. >> %dnsupdlog% 
      goto :endit 
      ) 
    set isfound=yes 
  ) 
) 

or looking at the file as it stands to me it seems you need to amend the tokens to use a bit. I have used more /T0 to remove the tabs. My output is as below:

@echo off
setlocal enabledelayedexpansion
set tab=
for /F "skip=1 tokens=1-3 delims=>= " %%A IN ('type dns2.txt ^| more /T0') DO ( 
  set A=%%A
  set B=%%B
  set C=%%C
echo #!A!#
echo #!B!#
echo #!C!#
)

#Addr#
#Count#
#1#
#Master[0]#
#1.2.3.4#
##

i.e. you want %%B and %%C for the first comparison and %%A and %%B for the second.

If you have an actual output file of the masters showing as it does to you with the extra CR's in then please post or email it (see profile) zipped up and will look.

Steve

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
Hmm, that didn't quite layout as intended!  Some of the waffle is at the bottom of the code area...

Happy new year, thought I'd take a look at messages while the Wizard of Oz is on the telly for the billionth time.

Steve
0
 
Steve BinkAuthor Commented:
My apologies for the delay.  When I get back into the office this evening, I will upload a zipped version of the sample output.
0
 
Steve BinkAuthor Commented:
Again, my apologies for the delay.  The zip file has two text files - one with just the MasterServers output, and the other with the full /zoneinfo output.  The only edits were for anonymization.  You can see the oddness in the full output, with only these particular lines using the extra 0x0d.
dnstext.zip
0
 
Steve BinkAuthor Commented:
BAH!  My text editor auto-corrected it for me.  I turned the feature off.  Try this again...
dnstext.zip
0
 
Steve KnightIT ConsultancyCommented:
Ah I wondered why .... only one 0D in there!  BTW I tried few of previous suggestions against it,

more --> tabs to spaces, all 0A go to 0d 0a
find --> all oa to 0d0a
type -> no change
more /t0 -> just 0a to 0d 0a
Will give it a check with what you have posted now instead.
0
 
Steve KnightIT ConsultancyCommented:
Yes I can see the issue now... will see what I can come up with.

Steve
0
 
Steve KnightIT ConsultancyCommented:
Ok, cant find any built in way of getting the extra 0D out.... BUT we can always just strip it off in the comparison, i.e.

@echo off
setlocal enabledelayedexpansion
set tab=
for /F "skip=1 tokens=1-3 delims=>= " %%A IN ('type dns.txt ^| more /t0') DO (
  set A=%%A
  set B=%%B
  set C=%%C

echo Native
echo.
echo #!A!#
echo #!B!#
echo #!C!#
echo.
echo With one char stripped
echo.
echo #!A:~0,-1!#
echo #!B:~0,-1!#
echo #!C:~0,-1!#
)

which gievs for me:

Native

#Addr#
#Count#
#1

With one char stripped

#Add#
#Coun#
#1#
Native

#IP#
#Addr[0]#
#1.2.3.4

With one char stripped

#I#
#Addr[0#
#1.2.3.4#
Native

#Command#
#completed#
#successfully.#

With one char stripped

#Comman#
#complete#
#successfully#

So we can use  this I think....

rem *** secondary domain exists.  Is it using this as master?  if not, skip
set isfound=no
for /F "skip=1 tokens=1-3 delims=>= " %%A IN ('"%plesk_bin%\dnscmd.exe" 5.6.7.8 /zoneinfo %1 MasterServers ^| more /t0') DO (
  set A=%%A
  set B=%%B
  set C=%%C
  echo DEBUG: A=#!A!#, B=#!B!#, C=#!C!#
  if /i "%%B"=="count" (if /i "%%C" NEQ "1" (
    echo Received unexpected master server count %%C!! >> %dnsupdlog%
    goto :endit
    )
  )
  if /i "%%B"=="Addr[0]" (
    if /i "!C:0,-1!" NEQ "%dnsupdip%" (
      echo Different master server !C:0,-1!.  No work to be done. >> %dnsupdlog%
      goto :endit
      )
    set isfound=yes
  )
)
if /i "%isfound%" NEQ "yes" (
  echo Did not find expected IP %dnsupdip% as master server.  No work to be done. >> %dnsupdlog%
  goto :endit
)

0
 
Steve KnightIT ConsultancyCommented:
Actually we need to strip the 0d off the count too of course so we need to use this on that line too.  Have removed the redundant fist token from my initial testing. Have also simplified by always stripping the last char off and just looking for shorter string, ie. Addr[0 instead of Addr[0 etc.
rem *** secondary domain exists.  Is it using this as master?  if not, skip
set isfound=no
for /F "skip=1 tokens=2-3 delims=>= " %%A IN ('"%plesk_bin%\dnscmd.exe" 5.6.7.8 /zoneinfo %1 MasterServers ^| more /t0') DO (
  set A=%%A
  set B=%%B
  set A=!A:~0,-1!
  set B=!B:~0,-1!
  if /i "!B!"=="coun" (if /i "!C!" NEQ "1" (
    echo Received unexpected master server count !C! >> %dnsupdlog%
    goto :endit
    )
  )
  if /i "!A!"=="Addr[0" (
    if /i "!B!" NEQ "%dnsupdip%" (
      echo Different master server !B!.  No work to be done. >> %dnsupdlog%
      goto :endit
      )
    set isfound=yes
  )
)
if /i "%isfound%" NEQ "yes" (
  echo Did not find expected IP %dnsupdip% as master server.  No work to be done. >> %dnsupdlog%
  goto :endit
)

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
Damn, left B and C in first check lines instead of A and B
rem *** secondary domain exists.  Is it using this as master?  if not, skip
set isfound=no
for /F "skip=1 tokens=2-3 delims=>= " %%A IN ('"%plesk_bin%\dnscmd.exe" 5.6.7.8 /zoneinfo %1 MasterServers ^| more /t0') DO (
  set A=%%A
  set B=%%B
  set A=!A:~0,-1!
  set B=!B:~0,-1!
  if /i "!A!"=="coun" (if /i "!B!" NEQ "1" (
    echo Received unexpected master server count !B! >> %dnsupdlog%
    goto :endit
    )
  )
  if /i "!A!"=="Addr[0" (
    if /i "!B!" NEQ "%dnsupdip%" (
      echo Different master server !B!.  No work to be done. >> %dnsupdlog%
      goto :endit
      )
    set isfound=yes
  )
)
if /i "%isfound%" NEQ "yes" (
  echo Did not find expected IP %dnsupdip% as master server.  No work to be done. >> %dnsupdlog%
  goto :endit
)

Open in new window

0
 
Steve BinkAuthor Commented:
That's exactly what I was looking for - the '!' syntax to grab substrings.  Thank you much!

0
 
Steve BinkAuthor Commented:
We still ended up using sed to clean up other aspects of the output, but this was important for a few reasons.  Thanks!
0
 
Steve KnightIT ConsultancyCommented:
No problem...  those are documented in the slightly unlikely place of set /? btw.  for /? and if /? hold lots of useful info. too for scripting in general.  You can use these with variables outside of loops using %var:~0,1% type syntax too, but within a loop you need delayedexpansion on and to sue ! ! as otherwise the variable doesn't appear to change during the loop at all.

Steve
0
 
Steve KnightIT ConsultancyCommented:
Oh and thans, you'e tipped me into a "master" certificate for "DNS".... never expected to have anything there!

Steve
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 12
  • 10
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now