Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: The syntax of the command is incorrect  (Read 13798 times)

0 Members and 1 Guest are viewing this topic.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
The syntax of the command is incorrect
« on: February 03, 2014, 09:07:26 AM »
Dear all
I created batch file to restart a lot of PCs,
when i tested it i found the batch is working fine till this host abc3s1or003 but after this host from abc3s1pd001 to the end of batch it give  the syntax of the command is incorrect and exit
I have checked  the lines and I did not find any error in writing,
Is it possible to help to fix this error.
I attached the file to any one want to help


[recovering disk space, attachment deleted by admin]

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: The syntax of the command is incorrect
« Reply #1 on: February 03, 2014, 09:17:55 AM »
Is this a continuation of your previous question?  If so, a moderator can combined the two questions into one thread to keep all the information in one place.
http://www.computerhope.com/forum/index.php/topic,142243.0.html

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: The syntax of the command is incorrect
« Reply #2 on: February 03, 2014, 09:25:37 AM »
Would probably help if you removed all the hard coded Line Feeds in your batch file.

[recovering disk space, attachment deleted by admin]

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: The syntax of the command is incorrect
« Reply #3 on: February 03, 2014, 10:02:03 AM »
Poor structure.
The OP should try to write an abstract outline of what hi is doing.
The abstract form will make clear the logic intended.
Batch files without documentation are not better, yet so many times this is what is often seen. Some Gurus can work that way, the rest of us need a clear explanation of what is going on.
To my knowledge, batch does not have a CASE block. Butnwe can imagine it.

Here is a possible pseudo-code for a CASE block.

Ifn the remote PC is number 44, go do the 44a update
Ifn the remote PC is number 37, go do the 37a update
Ifn the remote PC is number 09, go do the standard update
Say "No match found"


Of course that is not real code, but helps convey the idea.







Salmon Trout

  • Guest
Re: The syntax of the command is incorrect
« Reply #4 on: February 03, 2014, 03:34:02 PM »
This is not the way to write a batch file!

A set /p to get a hostname into %K%, then...

about 1200 lines like this...

IF /i %K%==abc3c301 ( SET k=abc3c301 & GOTO A ) 

If K=x set k=x (?!?!)

I know a better way (which is easier to debug!!!) but I don't even know if you are interested?






Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: The syntax of the command is incorrect
« Reply #5 on: February 03, 2014, 03:54:35 PM »
I am baffled myself as to why the op would set the variable K after he already checked that K was equal to what he is checking. Makes no sense to me. Variable names are case insensitive.
But yeah. Just like the last batch file they posted there is about 1000 lines of redundant code.

patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: The syntax of the command is incorrect
« Reply #6 on: February 03, 2014, 03:58:48 PM »
Merging the Topics would create even more cornfusion...just so you guys know...
I left it as is.
" Anyone who goes to a psychiatrist should have his head examined. "

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: The syntax of the command is incorrect
« Reply #7 on: February 03, 2014, 04:52:26 PM »
See the attachment for another way to do what your batch file does, in a simpler manner. 

These lines from

set "k="
to
:A

were changed


Make sure that you check the entry for the first term in these lines, as your batch file had mismatches on them. 
This list shows the two terms in your batch file that were being compared in the IF statements.


"abc3f2fc01c" "abc3f2fco1c"
"abc3f2fc01d" "abc3f2fco1d"
"abc3g1gh03s" "abc3g1gh035"
"abc3g1gh022" "abc3gigh022"
"abc3g2gf312" "abc3g3gf312"
"abc3g2gf313" "abc3g3gf313"
"abc3g2gf322" "abc3g3gf322"

- a couple are obvious typos but if any of them are right then some extra checking will be necessary in the code I provided.

[recovering disk space, attachment deleted by admin]

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: The syntax of the command is incorrect
« Reply #8 on: February 04, 2014, 06:23:27 AM »
I like what you did there Foxidrive.  I personally think it would make it easier if the OP would just put the list of computers in a text file and match it to the text file.  That way you are just editing the computer list when a new computer is put on the network versus screwing up the batch file.

Salmon Trout

  • Guest
Re: The syntax of the command is incorrect
« Reply #9 on: February 04, 2014, 11:33:24 AM »
1. The batch (59 lines)

@echo off
cls
mode 95,25
title :: Welcome
color 0b

:MENU

ECHO .
ECHO **********************************************************************************************
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO **This Batch To Restart PC write the name and press enter                                    *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO *                                                                                            *
ECHO **********************************************************************************************
ECHO..
ECHO..

set "k="
SET /P K="Write the name of PC And Press Enter (or press enter to quit): "
if not defined k goto :EOF

for /f "delims=" %%a in (machines.txt) do if /i "%k%"=="%%a" goto A

echo.
echo input not matched - try again
pause
cls
goto Menu

:A

ping -n 1 -l 32 -w 2000 -i 32 %k% > nul
IF %ERRORLEVEL%==0  GOTO Screens1
IF %ERRORLEVEL%==1  GOTO Screens2
CLS
GOTO MENU

:Screens1
shutdown -r -t 10 -c "Made by Eng Amin" -f -m \\%k%
cls
msg /time:5 * You will Restart Screens %k%
GOTO MENU

:Screens2
msg /time:4 *  Screens %k% is Offline
GOTO MENU


2. The file which contains the list of computers is attached (in the batch it is called machines.txt and should be in the same folder as the batch)

I show a portion here... the REMs are replaced by semicolons (FOR ignores lines which start with these)

abc3f10b
abc3f56a
abc3f56b

; F Door level 4*******************************************************************

abc3f31a
abc3f31b
abc3f32a
abc3f32b

; G Door level 3*******************************************************************

abc3g01a
abc3g01b





[recovering disk space, attachment deleted by admin]

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: The syntax of the command is incorrect
« Reply #10 on: February 04, 2014, 06:27:02 PM »
Another option would to just query Active Directory if the computer object exists in the domain. That way you wouldn't need alist of computers.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: The syntax of the command is incorrect
« Reply #11 on: February 07, 2014, 08:30:46 PM »
@Abo-Zead - Did you get a solution from this thread?

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: The syntax of the command is incorrect
« Reply #12 on: February 08, 2014, 05:26:52 PM »
This is not the way to write a batch file!

A set /p to get a hostname into %K%, then...

about 1200 lines like this...

IF /i %K%==abc3c301 ( SET k=abc3c301 & GOTO A ) 

If K=x set k=x (?!?!)

I know a better way (which is easier to debug!!!) but I don't even know if you are interested?

Dear Salmon Trout
i'm interested but i don't know how to use every  command the best use

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: The syntax of the command is incorrect
« Reply #13 on: February 08, 2014, 06:26:58 PM »
See the attachment for another way to do what your batch file does, in a simpler manner. 

These lines from

set "k="
to
:A

were changed


Make sure that you check the entry for the first term in these lines, as your batch file had mismatches on them. 
This list shows the two terms in your batch file that were being compared in the IF statements.


"abc3f2fc01c" "abc3f2fco1c"
"abc3f2fc01d" "abc3f2fco1d"
"abc3g1gh03s" "abc3g1gh035"
"abc3g1gh022" "abc3gigh022"
"abc3g2gf312" "abc3g3gf312"
"abc3g2gf313" "abc3g3gf313"
"abc3g2gf322" "abc3g3gf322"

- a couple are obvious typos but if any of them are right then some extra checking will be necessary in the code I provided.


thanks foxidrive for rebuild my batch with the correct commands, I get my solution from this batch you created and if I faced any problem i will never Hesitate to ask you .

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: The syntax of the command is incorrect
« Reply #14 on: February 09, 2014, 07:15:46 AM »
But did you realize what your initial mistake was? I pointed it out to you clear as day with a screen shot.