Re: new to scripting.. the below script stops after first run..



I had a feeling it might be something like that.. I vaguely remembered CALL from a long time ago, but wasnt sure if it was relevant or not.

I ended up achieving what I wanted to with some perl. I had one of the engineers here help get me started with the basics, then modified it, and combined it with windows shell.

Good to know about the calls for the future.

Much appreciated.


"Marty List" <nospam.martylist@xxxxxxxxxxxxxxxx> wrote in message news:OO7V%23IujIHA.5820@xxxxxxxxxxxxxxxxxxxxxxx

This is normal behavior for batch files is you don't add the CALL statement before each child script, like this:

call testdhcp.cmd ...
call testdhcp.cmd ...

Run "call /?" to see additional syntax.


"infinitiguy" <derek@xxxxxxxx> wrote in message news:3F7CBD2C-C197-4D2D-9396-D2F84BC18BBF@xxxxxxxxxxxxxxxx
I'm in the middle of migrating DNS and DHCP from unix services to MS DNS/DHCP.. I have exports from my unix servers that aren't compatible with MS for a straight import so I've fiddled with the data, and now I want to just run the same script many times and pass it a bunch of parameters.. below is what I have..
This script is called testdhcp.cmd.. I pass it 8 variables that get set as the below values
Set server=%1
Set netid=%2
Set subnetmask=%3
Set name=%4
Set comment=%5
Set gateway=%6
Set iprangestart=%7
Set iprangeend=%8
Echo creating the scope
Netsh dhcp server %server% add scope %netid% %subnetmask% %name% > NUL
Netsh dhcp server %server% scope %netid% set name %name% > NUL
Netsh dhcp server %server% scope %netid% set comment %comment% > NUL
Echo Changing scope options
Netsh dhcp server %server% scope %netid% add iprange %iprangestart% %iprangeend% BOTH > NUL
Netsh dhcp server %server% scope %netid% set optionvalue 003 IPADDRESS %gateway% > NUL

Echo Not Activating scope...
Netsh dhcp server %server% scope %netid% set state 0 > NUL

Echo Done!
-----------------------------
This above script is then run a bunch of times and the below values are passed from it. I have a cmd file named DublinScopes.cmd that contain the below entries
---------------------------------------------------
testdhcp.cmd \\iswin2k32 10.63.2.0 255.255.255.0 10.63.2.x Zurich 10.63.2.1 10.63.2.120 10.63.2.150
testdhcp.cmd \\iswin2k32 10.63.8.0 255.255.255.0 10.63.8.x Paris 10.63.8.1 10.63.8.125 10.63.8.150
testdhcp.cmd \\iswin2k32 10.63.11.0 255.255.255.0 10.63.11.x Madrid 10.63.11.1 10.63.11.75 10.63.11.100
testdhcp.cmd \\iswin2k32 10.63.7.0 255.255.255.0 10.63.7.x Chertsey 10.63.7.1 10.63.7.100 10.63.7.150
testdhcp.cmd \\iswin2k32 10.63.9.0 255.255.255.0 10.63.9.x Ffrankfurt 10.63.9.1 10.63.9.100 10.63.9.150
testdhcp.cmd \\iswin2k32 10.63.4.0 255.255.255.0 10.63.4.x Milan 10.63.4.1 10.63.4.100 10.63.4.150
testdhcp.cmd \\iswin2k32 10.63.13.0 255.255.255.0 10.63.13.x Roma 10.63.13.1 10.63.13.75 10.63.13.100
testdhcp.cmd \\iswin2k32 10.5.1.0 255.255.255.0 10.5.1.x Dublin 10.5.1 10.5.1.1 10.5.1.75 10.5.1.150
testdhcp.cmd \\iswin2k32 10.5.2.0 255.255.255.0 10.5.2.x Dublin 10.5.2 10.5.2.1 10.5.2.170 10.5.2.250
testdhcp.cmd \\iswin2k32 10.5.10.0 255.255.255.0 10.5.10.x Dublin test 10.5.10 10.5.10.1 10.5.10.101 10.5.10.254
testdhcp.cmd \\iswin2k32 10.2.0.0 255.255.0.0 10.2.x.x Dublin Ruleset 10.2.0.1 10.2.1.1 10.2.7.255
---------------------------------------------------
The first line passes fine, and spits out the below output(basically every command through the first script, with the proper values in place). What I don't understand is why it doesn't go down the list and finish the rest.. While the above isn't a big deal to copy and paste... I wanted to use this same method to feed 100 or so DHCP reservations through once the scopes were created, and I don't want to have to copy and paste that...
Any thoughts? Is there a way I can do this smarter? I know if I use a loop of some sorts I can, but Im not sure exactly how I'd do it in dos commands. I have a perl script that will probably do the trick, but I'd rather not have to use perl to do this if possible.



C:\>DublinScopes.cmd
C:\>testdhcp.cmd \\iswin2k32 10.63.2.0 255.255.255.0 10.63.2.x Zurich 10.63.2.1 10.63.2.120 10.63.2.150
C:\>Set server=\\iswin2k32
C:\>Set netid=10.63.2.0
C:\>Set subnetmask=255.255.255.0
C:\>Set name=10.63.2.x
C:\>Set comment=Zurich
C:\>Set gateway=10.63.2.1
C:\>Set iprangestart=10.63.2.120
C:\>Set iprangeend=10.63.2.150
C:\>Netsh dhcp server \\iswin2k32 add scope 10.63.2.0 255.255.255.0 10.63.2.x 1>NUL
C:\>Netsh dhcp server \\iswin2k32 scope 10.63.2.0 set name 10.63.2.x 1>NUL
C:\>Netsh dhcp server \\iswin2k32 scope 10.63.2.0 set comment Zurich 1>NUL
C:\>Netsh dhcp server \\iswin2k32 scope 10.63.2.0 add iprange 10.63.2.120 10.63.2.150 BOTH 1>NUL
C:\>Netsh dhcp server \\iswin2k32 scope 10.63.2.0 set optionvalue 003 IPADDRESS10.63.2.1 1>NUL
C:\>Echo Not Activating scope...
Not Activating scope...
C:\>Netsh dhcp server \\iswin2k32 scope 10.63.2.0 set state 0 1>NUL
C:\>Echo Done!
Done!
C:\>


.



Relevant Pages

  • Re: new to scripting.. the below script stops after first run..
    ... I have exports from my unix servers that aren't compatible with MS for a straight import so I've fiddled with the data, and now I want to just run the same script many times and pass it a bunch of parameters.. ... Echo Changing scope options ... Netsh dhcp server %server% scope %netid% add iprange %iprangestart% %iprangeend% BOTH> NUL ...
    (microsoft.public.windows.server.scripting)
  • Re: does not match the existing scope error at install!!
    ... start the 'Continue Setup' script on the desktop. ... existing scope on your DHCP server, which may result in the scope becoming ... Did you manually install DHCP Server on the server? ... Steve Foster [SBS MVP] ...
    (microsoft.public.windows.server.sbs)
  • dhcpobjs.dll: Problems accessing reservations in scopes larger than /24 (class C)
    ... reservations on a Win2000 DHCP server, and I was pretty happy with the ... I can access the scope information fine e.g. (assuming a scope address ... I try to access an individual reservation within scope 192.168.8.0, ... Where line 21 in the above script would be: ...
    (microsoft.public.scripting.vbscript)
  • Re: Name collisions in Monad
    ... We spent a lot of time working on the scoping rules in Monad. ... create a new scope when run, and variables _created_ in that new scope are ... script, call a function, or start a new instance of Windows Command ... $var is initially set to "init" in the function ...
    (microsoft.public.windows.server.scripting)
  • Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?
    ... > these activities have effects that are felt outside of the scope of a script ... Of course in script, the object will be ... > Even the above definition makes no distinction between object variables ... a connection every time I read or write a key, ...
    (microsoft.public.scripting.wsh)

Loading