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!
bbimisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
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.
0
Steve KnightIT ConsultancyCommented:
You have %G that will need to be %%G in  3 places for starters.

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbimisAuthor Commented:
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
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Line 4 contains several errors and potential failures.
for /R %%G IN (*.mdb) DO xcopy "%%~G" '\\%UserInput%\backup' && echo %%G >> c:\filelog.txt

Open in new window

0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Using single quotes will work in most cases, but the official way is to use double quotes.
0
bbimisAuthor Commented:
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!
0
NVITEnd-user supportCommented:
> Does '\\server\c\backup' specify a file name or directory name on the target
Add the /i switch to xcopy
0
NVITEnd-user supportCommented:
Are you also copying sub-folders from source "%%G"? If so, add the /e or /s switch.
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
If you want to make sure the target location for xcopy is a folder, even if it does not exist yet, append a backslash, like with:
   xcopy c:\payroll\some.mdb '\\%UserInput%\backup\'
0
Steven CarnahanNetwork ManagerCommented:
You may also want to declare a starting folder and include it in the For loop just in case you execute the program from a different folder and remember that using the /R will traverse the tree from the starting folder looking for *.mdb files.
0
NVITEnd-user supportCommented:
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)?
0
Steven CarnahanNetwork ManagerCommented:
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.
0
bbimisAuthor Commented:
Thanks I will look at it Monday and reward points have a good weekend
0
bbimisAuthor Commented:
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!
0
bbimisAuthor Commented:
thanks! all!
0
Steven CarnahanNetwork ManagerCommented:
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.
0
NVITEnd-user supportCommented:
thanks for the update, bbmis! Have a nice day.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.