i've cobbled together a batch file (pretty much a direct copy/paste off the various sites) to ping PCs from a txt file source and write the result to a log file (which are offline/online) etc
i've also got one working which copies a select file to a specific destination going through each hostname in a txt file too.
problem is i have no idea how to get logging working on the copy one. i've tried adding an echo line >> logfile.txt etc which just says successful - even if the PCs are offline.
e.g batch file that pings list of PCs in a file and returns result: (that works fine)
can anyone pls modify the 1st for me so it copies the file if the machines online but also writes to the log the hostname and success/lack thereof?
also - recommend a good site that actually guides you on building these yourself (for a noob on this kind of thing)?
i've also got one working which copies a select file to a specific destination going through each hostname in a txt file too.
problem is i have no idea how to get logging working on the copy one. i've tried adding an echo line >> logfile.txt etc which just says successful - even if the PCs are offline.
SET COPIED=successful
FOR /F %%X IN (servers.txt) DO (
copy /Y name.txt "\\%%X\C$\temp\"
IF ERRORLEVEL 1 SET COPIED=not successful
Echo File Copy %COPIED% to %%X >> Logfile.txt
)
@echo Completed.
pause
e.g batch file that pings list of PCs in a file and returns result: (that works fine)
@echo off
setlocal ENABLEEXTENSIONS
set OutputFile=logfile.txt
set ListFile=servers.txt
echo y|del %OutputFile%
for /f "tokens=1,2 delims= " %%a in (%ListFile%) do (
call :Sub "%%a" "%%b"
echo Checking "%%a" "%%b")
notepad "%OutputFile%"
goto :eof
:Sub
ping %1 -n 1 > NUL
if ERRORLEVEL 1 (
set state=boo
set name=%1
set IP=
) else (
set Name=%2
set state=On Line yay
set name=%1
)
echo %Name%,%state% %IP%,%2 >> "%OutputFile%"
goto :eof
can anyone pls modify the 1st for me so it copies the file if the machines online but also writes to the log the hostname and success/lack thereof?
also - recommend a good site that actually guides you on building these yourself (for a noob on this kind of thing)?