Solved

Reboot server if connection fails

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FileZilla port forwarding 22 190
Service not starting 6 65
Dell OpenManage 8.3 Windows 10 2 125
Best Practices: Windows 7 Workgroup to Windows 2012 R2 Essentials Migration 3 51
Have you ever stumbled upon a software that is so great that you just love? It happened to me. Love at first sight. Filezilla Server.   Ok its not the most advanced ftp server I've came across. But its a fairly simple piece of software to get the …
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

15 Experts available now in Live!

Get 1:1 Help Now