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

x
?
Solved

batch file to push host file to remote computer

Posted on 2009-04-09
2
Medium Priority
?
801 Views
Last Modified: 2012-05-06
Hi all, I have a need to push out a central host file to remote computers.

del results.txt
FOR /F %%a IN (list.txt) DO XCOPY /y c:\test2.txt \\%%a\c$\windows\system32\drivers\etc >> results.txt
echo %date% %time% %errorlevel%>>results.txt

This is what I have so far.  I would like the results.txt to list the computer name where the file was not copied....right now it says 0 File(s) copied.
I have 400 computers to run this on.....So I need to be able to identify which computers did not get the copy  for whatever reason...
0
Comment
Question by:bfpnaeechange
[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
2 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 24108873
del results.txt
FOR /F %%a IN (list.txt) DO (
  XCOPY /y c:\test2.txt \\%%a\admin$\system32\drivers\etc
  if errorlevel==1 then echo Error with %%a >> results
  echo %date% %time% %errorlevel%>>results.txt
  )
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24121681
sirbounty,
I do not believe that %errorlevel% in for will work, as variable substitution is performed when DO is reached, so errorlevel holds the state when FOR is executed.
You will have to use delayed expansion, as in first part of my Snippet.
I agree to your usage of admin$ share.

bfpnaeechange,
the second part is an alternative way to do it, avoiding errorlevel, and introducing some "improvements".


@echo off
setlocal EnableDelayedExpansion
del results.txt 2>nul >nul
FOR /F %%C IN (list.txt) DO (
  XCOPY /y c:\test2.txt \\%%C\admin$\system32\drivers\etc 
  if errorlevel 1 then echo Error with %%C >> results
  echo !date! !time! !errorlevel!>>results.txt
)
 
@REM -- Another way --
@echo off
setlocal EnableDelayedExpansion
FOR /F %%C IN (list.txt) DO (
  set line=!date! !time! %%C
  XCOPY /y c:\test2.txt \\%%C\admin$\system32\drivers\etc >nul 2>&1 || set line=!line! Error 
  echo !line!
) >results.txt

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

618 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