Solved

Reboot server if connection fails

Posted on 2014-10-09
4
141 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Introduction People like FTP.  It's a solid, stable, robust protocol for quickly transferring files between two hosts using TCP/IP.  In most cases it's much faster than SMB or CIFS, and certainly much easier to set up between organizations.  This…
If, like me, you have a lot of Dell servers in the estate you manage this article should save you a little time. When attempting to login to iDrac on any server I would be presented with two errors. The first reads "Do you want to run this applicati…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now