Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Reboot server if connection fails

I'm looking for an application that will allow me to have a windows server reboot if it cannot ping a specific ip or URL after a predesignated amount of time AND on a schedule of my choosing. What's available?
0
techindahaus
Asked:
techindahaus
  • 2
  • 2
1 Solution
 
KimputerCommented:
It sounds simple enough for a script (VBscript/Powershell), or even a program written in a free version of Visual Express would do.

Here's a very simple VBscript to start with:

On Error Resume Next

Dim strTarget, strPingResults
strTarget = "10.0.1.11" 'IP address or hostname

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
'	WScript.Echo strTarget & " responded to ping."  

Else
'	WScript.Echo strTarget & " did not respond to ping."
	Set WshExec = WshShell.Exec("shutdown /r /t 1") 'reboot within 1 second
End If

Open in new window


More logic and programming can be added if it's too simple. You can just schedule this as many times as you want.
0
 
techindahausAuthor Commented:
Thanks for the reply. What I was originally looking for was an application that would automate this for me. I was not able to, so I went with two scripts. One is a batch file and the other a vbs file that calls it so I could run silently. Here is what I did.

The VBS script:
Set WshShell = CreateObject("WScript.Shell" ) 
WshShell.Run chr(34) & "c:\batchfiles\autoreboot.bat" & Chr(34), 0 
Set WshShell = Nothing 

Open in new window


The Batch File it calls:
-------------------
REM: Reboot on Network Failure

@echo off

set /a counter=0

:start

ping google.com > %temp%\pinglog.txt

find "Reply from" < %TEMP%\pinglog.txt > nul

if errorlevel 1 (set /a counter=%counter%+1)

if not errorlevel 1 (set /a counter=0)

set /a timeout = 100 - %counter%

if %counter% GEQ 4 (echo System reboot imminent, please press ctrl-c in the next %timeout% seconds to abort)

if %counter% GEQ 100 (shutdown -r)

goto :start

-----------------

Open in new window

0
 
KimputerCommented:
Yes, that's basically the same. What feature is now lacking that you need a program to do it? Scheduled tasks controls the schedule, I don't see what other features you need?
0
 
techindahausAuthor Commented:
I was looking for an application but settled for two scripts to do the same job.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now