This stems from another person's work that I have adapted (rather poorly it would seem) to my own use - to copy a file to another computer on a good ping, and spit out a record when the ping fails so we can go back to that machine later, and go on to the next machine when it assesses one of those two outcomes:
I have found what I've put together doesn't loop back through the hostnames in the names.txt, it just does one host. Was just wondering how to set that up (tabs, or one name on each line, etc.), or if it was just a code error on my part (full code below). What I want it to do is to copy a file from one computer to another if the ping is good, skip to the next host name in names.txt if the ping times out while sending that note to a results.txt that the ping timed out, using this setup. So far it only goes through one hostname, and will copy the file regardless of if I can ping the host or not when I make the path at the end local instead of remote. Depending on my edits, probably my fault as I'm just getting into this, I'll get a result in my results.txt file that I got a non-response, but the file still copies, anyway... I know that the non-response is correct, but the file copying in that instance is not. Could I get some help cleaning this up a bit, please? Been working at it all night and would like another pair of eyes.
echo off
cls
REM Set the file paths here --
SET ResultsFile=C:\results.txt
SET MachineList=C:\names.txt
SET VirusChecker=C:\viruscheck
er.bat
REM Will error out if you do not have a names.txt machine list --
CLS
ECHO.
IF NOT EXIST "%MachineList%" (
ECHO Cannot locate Machine List: %MachineList%
PAUSE>NUL
GOTO EOF
)
REM Starting the procedure --
ECHO Processing all machine names in %MachineList% . . .
ECHO.
FOR /f "tokens=*" %%M in (%MachineList%) do CALL :CHECK "%%M"
goto :EOF
:CHECK
set Machine=%~1
set Machine=%Machine: =%
set TimeOut=
for /F "delims=" %%a in ('ping -w 1000 %Machine% ^| findstr "Request timed out"') do set TimeOut=Y
if not "%TimeOut%"=="Y" goto :dothecopy
echo %Machine% did not respond at %Time%>>%ResultsFile%
if %Machine%=="" goto :EOF
exit /b
:dothecopy
REM checks for VirusCheck.bat file at location specified --
ECHO Copying virus checker... please wait...
IF NOT EXIST "%VirusChecker%" (
ECHO Cannot locate Virus Checker: %VirusChecker%
PAUSE>NUL
GOTO EOF
)
copy %VirusChecker% \\%Machine%\c$\Docume~1\Al
lUse~1\Sta
rtM~1\Prog
rams\Start
up\virusch
ecker.bat
:EOF
pause
cls
exit
This will help our IT security guy be able to send out startup batch scripts through our network. I'd give it more points, but all I've got is 105, plus this did stem from another thread where they accepted the answer either before fully testing it, or they just knew what they were doing when they got the answer and put it together as they needed it, which was slightly different than my implementation. Either way, I appreciate the help. -Tom
Start Free Trial