Page 1 of 1

%%A not translating as variable

Posted: 02 Jun 2011 06:33
by technotika
Hi ,

I'm struggling to get a batch file to run against a list of hostnames

heres some code where the issue occurs

@echo on
for /f %%A in (C:\hosts.txt) do
xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%%a\C$\Temp"

and here is the error

C:\WINDOWS\system32>xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdm
inistrator-2.0.5.msi" "\\%a\C$\Temp"
Invalid drive specification
0 File(s) copied

As you can see the %%A doesn't bring the computer name listed in the hosts.txt file, where I would expect \\PCNAMEEG\C$\Temp Im getting %A as the pcname and thus the fail. I have played around with different things but cant get to the bottom of it?


Any tips would be great...thanks.

Re: %%A not translating as variable

Posted: 02 Jun 2011 06:55
by jeb
Sometimes it's hard to see ... :)

%%A <> %%a

It's case sensitive

jeb

Re: %%A not translating as variable

Posted: 02 Jun 2011 07:09
by technotika
thanks for quick response...still no joy

code test

@echo on
E:\PsexecTMA>for /F %A in (C:\hosts.txt) do Echo %A

E:\PsexecTMA>Echo COMPNAME <SUCCESS there but.....
Z1012030

xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%%A\C$\Temp"
E:\PsexecTMA>pause
Press any key to continue . . .

E:\PsexecTMA>xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%A\C$\Temp"
Invalid drive specification
0 File(s) copied


ACTUAL CODE
@echo on

for /f %%A in (C:\hosts.txt) do Echo %%A

pause

xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%%A\C$\Temp"

Re: %%A not translating as variable

Posted: 02 Jun 2011 07:19
by dbenham
It looks like you are missing ( ) to group multiple commands in your FOR loop DO section. As originally written your XCOPY line is not part of the FOR loop.

Code: Select all

@echo on
for /f %%A in (C:\hosts.txt) do (
  Echo %%A
  pause
  xcopy /herky "C:\BUILDS\TMA HHDC Applications\ConsumptionAdministrator-2.0.5.msi" "\\%%A\C$\Temp"
)


Dave Benham

Re: %%A not translating as variable

Posted: 02 Jun 2011 07:33
by technotika
FANTASTIC - thank you very much

So if I have loads of commands to do for each machine in the hosts.txt

as long as I have it all in ( ) It's all good e.g.

@echo off

for /f %%A in (C:\hosts.txt) do (
code code code code code codecode code codecode code codecode code code
pause
code code codecode code codecode code codecode code codecode code code
pause
code code codecode code codecode code codecode code codecode code code
pause
)