+
  
SERVICES
  
PRODUCTS
  
CONTACT US

Batch Script – Wait for ping response and then run a command

by Chris Hall/December 1, 2016


@echo off

rem REPLACE PC NAME/IP ADDRESS BELOW WITH REQUIRED.
set pc_name=192.168.1.1

:start
echo Please wait, testing if PC is online.
cls
ping -n 1 %pc_name% > nul
if %errorlevel% == 0 goto run_command
echo.
echo PC is currently offline.
echo.
echo Waiting 120 seconds…
ping -n 120 127.0.0.1 > nul
goto start

:run_command
cls
echo PC is online. Waiting 60 seconds for services to start.
echo.
ping -n 60 127.0.0.1 > nul
echo.
echo Running command…
echo.

REM COMMAND TO RUN GOES HERE.

goto END

:END
pause

← Back to News



Leave a comment

Your email address will not be published. Required fields are marked *


Want to say hey or find out more?


If you're part of a small/medium or enterprise level we
can help address your IT Management needs.

Get in touch
    
View our Services
                
Make your data
work for you.
Contact Us

+61 438 661 875
inquiries@datacommand.com.au

     

Copyright © DataCommand Pty Ltd / Privacy Policy
ABN 98 205 256 068 / ACN 131 977 323