Solved

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

Posted on 2016-09-12
5
84 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 84

Accepted Solution

by:
oBdA earned 500 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 84

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
shell script 2 52
AWK:  END { statements } 2 28
Need help Creating a Powershell script 8 63
if then inside for loop not working - Batch scripting 8 29
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…

730 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