?
Solved

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

Posted on 2016-09-12
5
Medium Priority
?
141 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…

752 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