Solved

Reboot server if connection fails

Posted on 2014-10-09
4
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Samba is the de-facto standard program (or, more correctly: suite of programs) that UNIX and Linux systems use to share files with Microsoft Windows (and more recently, Mac OS-X) systems. Currently, there are 2 common versions of Samba available,…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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