Solved

Reboot server if connection fails

Posted on 2014-10-09
4
148 Views
Last Modified: 2014-10-15
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
Comment
Question by:techindahaus
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 40372482
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
 

Accepted Solution

by:
techindahaus earned 0 total points
ID: 40373230
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
 
LVL 35

Expert Comment

by:Kimputer
ID: 40373236
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
 

Author Closing Comment

by:techindahaus
ID: 40381707
I was looking for an application but settled for two scripts to do the same job.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface There are many applications where some computing systems need have their system clocks running synchronized within a small margin and eventually need to be in sync with the global time. There are different solutions for this, i.e. the W3…
Hello, As I have seen there a lot of requests regarding monitoring and reporting for exchange 2007 / 2010 / 2013 I have decided to post some thoughts together and link to articles that have helped me. Of course a lot of information you can get…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question