Link to home
Start Free TrialLog in
Avatar of bbimis
bbimis

asked on

keep getting an error the syntax of the command is wrong

i have the following code where i'm trying to look for files and move them to a shared server. i keep getting an error about incorrect syntax. i'm trying to execute the bat file through psexec
here is what i have
@echo off
REM COPY Database Files from Manager System to Training Computer and generate log
set /p UserInput="enter server computer ip address: "
for /R %G IN (*.mdb) DO xcopy "%G" '\\%UserInput%\backup' echo %G >> c:\filelog.txt

echo Database Files copied
 
REM COPY PAYROLL DB
xcopy c:\payroll\some.mdb '\\%UserInput%\backup'
echo payroll database file copied

REM COPY ini files
xcopy c:\windows\some.ini '\\%UserInput%\backup'
xcopy c:\windows\another.ini '\\%UserInput%\backup'
echo ini files copied

REM Copy the My Documents Directory to the training computer
xcopy 'C:\Documents and Settings\Manager\My Documents' '\\%UserInput%\backup'
echo mydocuments files copied

Open in new window


thanks!
Avatar of NVIT
NVIT
Flag of United States of America image

I assume it runs fine without psexec.

What does your psexec line look like?

For debugging purposes, just run...
psexec cmd /k

Open in new window


Add the -u switch if needed.

This opens a cmd prompt as the user.

Then, run your bat file and see what errors show.
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bbimis
bbimis

ASKER

no it says the syntax of  the command is incorrect.
with the cmd /k command i get the filename, directory name, or volume label syntax is incorrect.

i'm sure the issue is with my variable use
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using single quotes will work in most cases, but the official way is to use double quotes.
Avatar of bbimis

ASKER

when i do enter the computername or ip address i get the following error
Does '\\server\c\backup' specify a file name or directory name on the target (F=File, D=Directory)

thanks!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you also copying sub-folders from source "%%G"? If so, add the /e or /s switch.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes. per Qlemo's post re: using the backslash. It works for single or multiple files. The /i switch just works for multiple files. Just use the backslash.

Also, since you're traversing folders, and each file is copied to the same folder, you aren't covering for potential duplicate filenames. If one is found, xcopy will prompt you to Overwrite  (Yes/No/All)?
One more thing.  the "echo" lines, after the first one, are not pointing to the log file so they would just display on screen.  Lines 10, 15 and 19.
Avatar of bbimis

ASKER

Thanks I will look at it Monday and reward points have a good weekend
Avatar of bbimis

ASKER

pony10us: as for the starting folder being the root dir. wouldn't it be for c:\ /R ...... ?
As you can tell i'm still learning this. Thanks!
Avatar of bbimis

ASKER

thanks! all!
Thank you for the points

as for the starting folder being the root dir. wouldn't it be for c:\ /R ...... ?

If you are looking for *.mdb anywhere on the C: drive then you could do "c:\ /R" however that would negate the need for the PAYROLL section since it is looking for a *.mdb as well and it would have already been found and acted upon.

Also, you may find that it will take longer to search the entire drive and may (probably will) find a lot of *.mdb files you don't want.
thanks for the update, bbmis! Have a nice day.