Question

GOTO was unexpected at this time.

Asked by: keerwen

I am working on a batch file to run a program from the local servers on each subnet.  The base of the code was copied directly from another question  here on Experts.  The code itself does not want to run one it gets to the goto command.  Heres a copy of my code  If REM the first two lines and un REM the next two i will get errors  on those either a syntax error or unexpected | error.  Any help would be great.

IPCONFIG |FIND "IP" >TEMPIP.tmp

set IP=%% iecho %IP% >> c:tempip.tmp

REM for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| find "IP Address"') do set GetIP=%%d
 
REM do set IP=%% iecho %IP% >> c:tempip.tmp
for /f "tokens=3 delims=." %%j in (c:\tempip.tmp) do set SUBNET=%%j



if %SUBNEt%==10 goto 10subnet
if %SUBNET%==12 goto 12subnet
if %SUBNET%==14 goto 14subnet
if %SUBNET%==16 goto 16SUBNET
if %SUBNET%==11 goto 11subnet
if %SUBNET%==15 goto 15subnet
goto ALL_USERS

:16SUBNET
"\\sn1-100835\Apps Installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 16 subnet!
goto ALL_USERS

:12SUBNET
"\\sy1-100998\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 100 subnet!
goto ALL_USERS

:10SUBNET
"\\sm1-100997\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS

:14SUBNET
"\\sa1-100977\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.msp"
echo Welcome to the 250 subnet!
goto ALL_USERS


:15SUBNET
"\\sl1-100239\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS

:ALL_USERS
REM Use this section to perform functions that pertain to all users
goto END

:END


Thanks!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-06-04 at 09:19:47ID23457323
Topic

Windows Batch Scripting

Participating Experts
4
Points
500
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. double quote (") in delims list !!!
    I want to parse a file and use the double quote (") as a delimiter...but I cannot use the line like : FOR /F "eol=; tokens=1* delims="" because the options are already between double quotes and this is causing a syntax error ! How can I manage that ?? ...
  2. Batch GOTO Problem
    I'm sure this is easy, so dont point and laugh. But i'm getting aggravated at this little problem i'm having. When i debug my batch file a error shows that "goto was unexpected at this time" right here: if not %test%==%name% goto create why in the world is this h...
  3. DOS batch file: was unexpected at this time error using IF…
    Hi, I am trying to set up a batch file that uses schematron to validate xml data. However, I am having some trouble with the DOS command syntax, I keep getting an error message "was unexpected at this time" at various points in my program depending on where I put ...
  4. Plot section and 3D surface in Autodesk Land Desktop Suite
    Can anyone please tell me how to draw cross-section at a line on contour plotted in AutoCAD *.dwg format using Autodesk Land Desktop. I also want to know how to create the 3D surfaces of natural ground and design grading using the contour plotted in AutoCAD file with the Ter...
  5. ) was unexpected at this time syntax error with cleanup bat
    I've almost got my cleanup bat working. I'm getting a ") was unexpected at this time" at the "for /F "tokens=1,2 delims= " %%i in ('dir %%X\%SRC5%\*.*') do if (%%j)==(File(s)) set _Count=%%i" line. Ideas? Thanks. @echo off SET SRC1=C:\Profile...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: knightEknightPosted on 2008-06-04 at 10:42:51ID: 21712282

your labels cannot begin with numeric characters ... try adding an _ to the front-end:

:_16SUBNET

 ...  goto _16SUBNET

 

by: keerwenPosted on 2008-06-04 at 11:27:15ID: 21712654

Sorry but that didn't do it.  Same error of got was unexpected at this time

 

by: knightEknightPosted on 2008-06-04 at 11:29:07ID: 21712675

hmm ... change your labels to all begin with an Alpha character instead, then post your changes.

 

by: keerwenPosted on 2008-06-04 at 11:29:46ID: 21712680

From what it looks like is that the subnet is not actually getting set.

 

by: keerwenPosted on 2008-06-04 at 11:30:20ID: 21712686

IPCONFIG |FIND "IP" >TEMPIP.txt

set IP=%% iecho %IP% >> c:\tempip.txt

REM for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| find "IP Address"') do set GetIP=%%d
 
REM do set IP=%% iecho %IP% >> c:tempip.tmp
for /f "tokens=3 delims=." %%j in (c:\tempip.txt) do set SUBNET=%%j



if %SUBNEt%==10 goto mchenry
if %SUBNET%==12 goto yyorkville
if %SUBNET%==14 goto austin
if %SUBNET%==16 goto newlenox
if %SUBNET%==11 goto Chicago
if %SUBNET%==15 goto atlanta
goto ALL_USERS

:newlenox
"\\sn1-100835\Apps Installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 16 subnet!
goto ALL_USERS

:yorkville
"\\sy1-100998\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 100 subnet!
goto ALL_USERS

:mchenry
"\\sm1-100997\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS

:austin
"\\sa1-100977\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.msp"
echo Welcome to the 250 subnet!
goto ALL_USERS


:Atlanta
"\\sl1-100239\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS



:chicago
"\\sc1-100576\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS

:ALL_USERS
REM Use this section to perform functions that pertain to all users
goto END

:END

 

by: knightEknightPosted on 2008-06-04 at 11:33:35ID: 21712715


setlocal enabledelayedexpansion

IPCONFIG |FIND "IP" >TEMPIP.txt

set IP=%% iecho %IP% >> c:\tempip.txt

REM for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| find "IP Address"') do set GetIP=%%d
 
REM do set IP=%% iecho %IP% >> c:tempip.tmp
for /f "tokens=3 delims=." %%j in (c:\tempip.txt) do set SUBNET=%%j



if !SUBNET!==10 goto mchenry
if !SUBNET!==12 goto yyorkville
if !SUBNET!==14 goto austin
if !SUBNET!==16 goto newlenox
if !SUBNET!==11 goto Chicago
if !SUBNET!==15 goto atlanta
goto ALL_USERS

:newlenox
"\\sn1-100835\Apps Installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 16 subnet!
goto ALL_USERS

:yorkville
"\\sy1-100998\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 100 subnet!
goto ALL_USERS

:mchenry
"\\sm1-100997\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS

:austin
"\\sa1-100977\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.msp"
echo Welcome to the 250 subnet!
goto ALL_USERS


:Atlanta
"\\sl1-100239\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS



:chicago
"\\sc1-100576\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS

:ALL_USERS
REM Use this section to perform functions that pertain to all users
goto END

:END

 

by: keerwenPosted on 2008-06-04 at 11:50:33ID: 21712874

Thre script completes but the program never runs.  The other item i'm seeing is the iecho is duplicating after each run.

 

by: knightEknightPosted on 2008-06-04 at 11:51:45ID: 21712884

I was just looking at that too.

 

by: keerwenPosted on 2008-06-04 at 14:07:18ID: 21714156

Well it is the subnet call it's not retreiving the correct information hence the issue.  Now i just need to find the correct commands to set the subnet.

 

by: keerwenPosted on 2008-06-04 at 14:43:17ID: 21714405

Found a solution  The subnet variable was not working correctly.  Changing the variable to pull from an echo of the ip address variable fixed the issue.



FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG /ALL ^| FIND "IP Address"') DO FOR %%B IN (%%A) DO SET IPADDR=%%B
ECHO IP address: %IPADDR%



for /f "TOKENS=3* DELIMS=." %%j in (echo %IPADDR%) do set subnet=%%k
echo SUBNET IS: %subnet%



if %SUBNEt%==10 goto mchenry
if %SUBNET%==12 goto yorkville
if %SUBNET%==14 goto austin
if %SUBNET%==16 goto newlenox
if %SUBNET%==11 goto Chicago
if %SUBNET%==15 goto atlanta
goto ALL_USERS

:newlenox
"\\sn1-100835\Apps Installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 16 subnet!
goto ALL_USERS

:yorkville
"\\sy1-100998\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 100 subnet!
goto ALL_USERS

:mchenry
"\\sm1-100997\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS

:austin
"\\sa1-100977\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.msp"
echo Welcome to the 250 subnet!
goto ALL_USERS


:Atlanta
"\\sl1-100239\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS



:chicago
"\\sc1-100576\apps installs\Engineering\AutoCAD\Patches\AutoDesk Land Desktop 2008\ldc2008_sp2.exe"
echo Welcome to the 250 subnet!
goto ALL_USERS

:ALL_USERS
REM Use this section to perform functions that pertain to all users
goto END

:END

 

by: keerwenPosted on 2008-06-05 at 08:07:00ID: 21720384

Hmmmm the batch file isn't working now.  The subnet is not being set correctly.  Tho yesterday it had no problems running at all.

 

by: sirbountyPosted on 2008-06-05 at 20:43:52ID: 21726056

Try changing this line
for /f "TOKENS=3* DELIMS=." %%j in (echo %IPADDR%) do set subnet=%%k
to read
for /f "TOKENS=3* DELIMS=." %%j in ("%IPADDR%") do set subnet=%%k

Additionally, alter this section:

if [%SUBNEt%]==[10] goto mchenry
if [%SUBNET%]==[12] goto yorkville
if [%SUBNET%]==[14] goto austin
if [%SUBNET%]==[16] goto newlenox
if [%SUBNET%]==[11] goto Chicago
if [%SUBNET%]==[15] goto atlanta
goto All_Users

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: dragon-itPosted on 2008-06-05 at 22:55:32ID: 21726527

Well IMO  that still doesn't work, though only in that it picks up the last octet (host) rather than the others.  What I would do I think is this:

Steve


@echo off
REM Pickup IP address.  Is last address showing in IPCONFIG if more than one.  If you want the first remove the REM below 
FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG /ALL ^| FIND "IP Address"') DO SET IPADDR=%%A & REM goto next
:next
ECHO IP address is now set to: %IPADDR%
 
REM  Split this up into the four octets.
for /f "TOKENS=1-4 DELIMS=." %%a in ("%IPADDR%") do set octet1=%%a & set octet2=%%b & set octet3=%%c & set host=%%d
 
REM Display split up IP address
echo Subnet details: %octet1% %octet2% %octet3% %host%
 
REM Choose which octet you call the subnet
set subnet=%octet3%
 
REM Call site label based on the subnet set.
echo calling Site %subnet%
goto Site%subnet%
 
:Site10
  echo At Site %subnet%
goto AllUsers
 
:Site11
  echo At Site %subnet%
goto AllUsers
 
:Site12
  echo At Site %subnet%
Goto AllUsers
 
:Site
REM This will be called if subnet can't be set for some reason
echo Unable to fins site details
Goto AllUsers
 
:AllUsers
REM All Users bit

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:

Select allOpen in new window

 

by: canaliPosted on 2008-06-06 at 13:17:15ID: 21732348

the last

@echo off
setlocal
set octet=3
for /f "tokens=2 delims=[]" %%I in ('ping -n 1 %computername%^|find "["') do for /f "tokens=%octet% delims=." %%a in ('echo %%I') do goto :Site%%a
 
:Site192
  echo At Site 192
goto AllUsers
 
:Site11
  echo At Site 11
goto AllUsers
 
:Site12
  echo At Site 12
Goto AllUsers
:Site1
  echo At Site 1
Goto AllUsers
 
:Site
REM This will be called if subnet can't be set for some reason
echo Unable to fins site details
Goto AllUsers
 
:AllUsers
REM All Users bit
echo all user
:END

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:

Select allOpen in new window

 

by: keerwenPosted on 2008-06-09 at 05:54:37ID: 31464024

This is a partial fix the other item was changing the k and j to be the same letter.

 

by: dragon-itPosted on 2008-06-09 at 06:14:00ID: 21742869

Interssting choice of answer. WHat did you use in the end?

Steve

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...