Autosensing reboot batch file :)

FireExit

Weaksauce
Joined
Sep 28, 2005
Messages
80
Morning all (well it is where I am anyway)

I have a small problem. I'm currently running a small webserver of my home internet connection and due to various reasons which I havn't worked out yet the machine seems to keep freezing, or at least it stops responding to pings and remote desktop connection attempts.

What I am looking to do is have a batch file run as a schedulded task that would PING from the local machine to its ip address. If it thens recieves dropped packets, it would call the SHUTDOWN -R command to reboot the box automatically.

Now my problem comes here.

How do I get the batch file to recognise that the PING attempt has failed and allow the SHUTDOWN command to run? I'm planning on using IF for the test itself, but i'm unsure of how to get it to look for the failed PING.

Any ideas?

Cheers

FireExit
 
Code:
@echo off
:Loop
ping SERVERNAME > %TEMP%\IPRes.txt
FINDSTR /C:"Request timed out" %TEMP%\IPRes.txt
IF NOT ERRORLEVEL 1 goto Restart
goto Loop
:Restart
shutdown -r -f -t 5 -m \\SERVERNAME
goto Loop

You also might want to download a small program called sleep.exe to pad the loop some.
 
Excelent - Thanks for that...

I'll give that a shot when I get back to the machine tonite :)

Thanks again
 
Back
Top