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.
%%A not translating as variable
Moderator: DosItHelp
Re: %%A not translating as variable
Sometimes it's hard to see ...
%%A <> %%a
It's case sensitive
jeb
%%A <> %%a
It's case sensitive
jeb
-
- Posts: 10
- Joined: 02 Jun 2011 06:22
Re: %%A not translating as variable
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"
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
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.
Dave Benham
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
-
- Posts: 10
- Joined: 02 Jun 2011 06:22
Re: %%A not translating as variable
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
)
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
)