Bat for network copy only on hosts that ping

0

Hey, I'm trying to make a script to copy a file from the desktop of the PC to other computers on the network, but I want to copy only the computers that ping, for example, if the pc dribbles it copy, otherwise it skips this host goes to the other.

This is working, but if the machine is off, the bat will wait and I want to skip if it does not ping.

@echo ----------------------------------------------------------------------
@echo Voce esta prestes a copiar o "CMD" para todas as maquinas.
@echo.
@echo Tem certeza que deseja fazer isso?
@echo ----------------------------------------------------------------------
@echo.

choice /C SN /M "Sim/Nao "

IF errorlevel=2 goto NAO
IF errorlevel=1 goto SIM

:SIM
echo Você escolheu SIM..
echo.


FOR /L %%C IN (10,1,60) DO 
(
    echo estacao%%C
    copy cmd.cmd \estacao%%C\c$\Users\Public\Desktop\

)

:NAO
exit

I can not get the ping state to validate.

@echo ----------------------------------------------------------------------
@echo Voce esta prestes a copiar o "CMD" para todas as maquinas.
@echo.
@echo Tem certeza que deseja fazer isso?
@echo ----------------------------------------------------------------------
@echo.

choice /C SN /M "Sim/Nao "

IF errorlevel=2 goto NAO
IF errorlevel=1 goto SIM

:SIM
echo Você escolheu SIM..
echo.


FOR /L %%C IN (10,1,60) DO 
(
    echo estacao%%C

    ping -n 1 estacao%%C

    IF not %ERRORLEVEL% == 1 (
        copy cmd.cmd \estacao%%C\c$\Users\Public\Desktop\
    )
)

:NAO
exit
    
asked by anonymous 11.03.2018 / 16:13

2 answers

0

Instead of using IF not %ERRORLEVEL% == 1 use IF %ERRORLEVEL% neq 1 (AÇÃO)
it may not work, but it was done to check the existence of files. ex: IF NOT EXIST file.txt (AÇÃO) Else (AÇÃO2)

    
14.03.2018 / 09:19
0
  

Follow the script that will identify machines on the network

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /L %%R IN (1,1,254) DO (
ping -n 1 192.168.1.%%R | find "TTL">pings.txt

set host=%%R
set /p ip=<pings.txt

if "!ip:~0,8!" equ "Resposta" (
ECHO. IP 192.168.1.%%R DEU REDE !
if !host! neq 5 (echo. copiou))


SET ip=
TITLE 192.168.1.%%R
)
  

In neq 5 you will change the 5 to the end of the ip of your machine,   this will tell the script that you do not want   that your machine is part of the process,   only the rest of the network.

     

In echo. copiou you will delete this information and add the command   which will copy the file.

    
14.03.2018 / 09:27