Reboot / Shutdown PC if Router unreachable

Netgear / Dg834g
October 9, 2010 at 04:35:43
Specs: Windows XP SP3, 4000+ / 2gb DDR
Can someone please help me with this batch, to reboot a computer in the event the network goes offline, or to shut it down, I do not know at this point why my network is crashing after about one day perhaps due to driver or cache problem this is meant as a temporary fix until I can find out why it is happening.

My intention is to ping my ROUTER i.e. www.routerlogin.com but here I am using the i.p.
but is seems to not be working correctly.

@echo off

ping -n 10.10.2.1 > null
if errorlevel 1 goto online
goto offline
*************************************
:online
echo NETWORK IS ONLINE
sleep 5
cls
goto eol

:offline
echo NETWORK IS OFFLINE
sleep 5
shutdown -r -f

**************************

Michelle


See More: Reboot / Shutdown PC if Router unreachable

Report •

#1
October 9, 2010 at 05:07:08
Ping, for whatever goofy reason, only returns non zero if it fails to resolve.

So you need something like this.

=======================================
@echo off & setLocal EnableDELAYedeXpansion

ping -n 1 yahoo.com | find "Reply" > nul
goto :!errorlevel!

:1
echo down
goto :eof

:0
echo up


=====================================
Helping others achieve escape felicity

M2


Report •

#2
October 9, 2010 at 05:24:39
Hey Mechanix2Go

THANK YOU so much :) it's funny I Just found this works after reading one of your old posts :D I am pinging my ISP's Gateway to verify their is Internet available through my router, sorry for my late reply as it seems my ISP email server is down too and never got an email from them, was coming to let you know I found the solution then saw your reply above THANK YOU THANK YOU :)

I will make a note of this reply too in case it works better ...

All the Best Michelle xxx

@echo off
echo.
ping -n 1 213.123.110.186 > null
goto %errorlevel%
echo.
:: *************************************
echo.
:0
echo NETWORK IS ONLINE
sleep 5
cls
goto eol

:1
echo NETWORK IS OFFLINE
sleep 5
:: shutdown -r -f
:eol
cls


Report •

#3
October 9, 2010 at 05:31:55
BTW,

The bit bucket in XP is NUL, not NULL.


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
October 9, 2010 at 05:47:45
ahh thanks will amend that :)

Michelle


Report •

#5
October 16, 2010 at 02:46:14
Dear Mechanix2Go
I copied this from one of your earlier posts, but I don't want to delete all directories of a gien name just those under a single path, see below!

Mechanix2Go July 15, 2005 at 10:35:36

::== nojunk.bat
@echo off

dir /s/b/ad \junk*.* > junklist
for /f %%J in (junklist) do del %%J /Q
::==

M2

*********************** This is what I need *******************
I have not got this right can you help ?

:: SET
set mig=G:\sort\Migrate\
:: ALL SUB-DIRECTORIES BELOW Migrate

:: PATH
G:
cd %mig%

:: COMMAND

dir /s/b/ad \%mig%*.* > junklist
for /f %%J in (junklist) do del %%J /Q

Mihelle <3


Report •

#6
October 16, 2010 at 02:48:45
Hi M2 can you help here ?

http://www.computing.net/answers/pr...

Chelley


Report •

#7
October 16, 2010 at 03:17:34
If you want to delete all directories below G:\sort\Migrate, try:

=========================================

@echo off & setLocal enableDELAYedeXpansion

pushd G:\sort\Migrate

for /f "tokens=* delims= " %%a in ('dir/b/ad') do (
echo rd /s /q "%%a"
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#8
October 19, 2010 at 12:47:59
Thanks so much Mechanix2Go

Again you saved my bacon :) thanks.

Michelle


Report •

Ask Question