Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Xcopy - from server share to multiple IP's using batch file (not working)

Posted on 2016-09-12
5
Medium Priority
?
190 Views
Last Modified: 2016-09-12
hi guys,

I'm using a script created by OdBA, which I then modified based on the help I got here. I am merely trying to copy the files from a server share on a domain to multiples of PC's on the same domain.

Here is the script. In the location C:\Temp\machines.txt is where I put the IP address of the computer(s). I've only put one IP in there for now. The script runs, but nothing is copied.

@echo off
setlocal enabledelayedexpansion
set MachineFile=C:\Temp\machines.txt
set LogFile=C:\Temp\machines.csv
>"%LogFile%" echo "Machine","State","Errorlevel"
for /f %%a in ('type "%MachineFile%"') do (
      echo Processing %%a ...
      ping.exe -4 -n 2 %%~a | find /i "TTL" >NUL
      if errorlevel 1 (
            >>"%LogFile%" echo "%%~a","Offline","n/a"
      ) else (
            ECHO xcopy \\server\share\filename \\%%~a\c$\temp /e
            >> "%LogFile%" echo "%%~a", "online", "!ErrorLevel!"
)
)
echo Done.

Any ideas guys?

Thanks a lot
Yashy
0
Comment
Question by:Yashy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 41794002
The script is in test mode and will only echo the xcopy command it would normally run. Remove the uppercase ECHO in line 12 to run it for real.
@echo off
setlocal enabledelayedexpansion
set MachineFile=C:\Temp\machines.txt
set LogFile=C:\Temp\machines.csv
>"%LogFile%" echo "Machine","State","Errorlevel"
for /f %%a in ('type "%MachineFile%"') do (
	echo Processing %%a ...
	ping.exe -4 -n 2 %%~a | find /i "TTL" >NUL
	if errorlevel 1 (
		>>"%LogFile%" echo "%%~a","Offline","n/a"
	) else (
		ECHO xcopy "\\server\share\filename" "\\%%~a\c$\temp" /e
		>> "%LogFile%" echo "%%~a", "online", "!ErrorLevel!"
	)
)
echo Done.

Open in new window

If you post scrips, please enclose them in "Style Code" tags (see the tool bar above the Comment field).
0
 
LVL 1

Author Comment

by:Yashy
ID: 41794029
Aah...sir OdBA:).

I did take out the ECHO, but then when I run the batch file, the actions is constantly looping and it doesn't copy the file. So the command prompt is merely running the xcopy and says 'Processing' with a load of writing and then reruns the same thing over and over without doing anything.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 41794034
You didn't name the batch file xcopy.cmd or xcopy.bat? If so, rename it to something that is not a native Windows command.
0
 
LVL 1

Author Comment

by:Yashy
ID: 41794040
I've renamed it and it does the same thing sadly.
0
 
LVL 1

Author Comment

by:Yashy
ID: 41794041
Ignore!!!

I've got it working. It may have been folder permissions stopping it. All good matey. Thank you:))
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question