Solved

Auto restart computer if ping fails

Posted on 2014-12-17
5
243 Views
Last Modified: 2015-01-13
We have a remote server (1hr drive) for a surveillance system.  For some reason it randomly goes offline.  The only fix at the moment is to restart.  No error logs at all.  Router works because we can bring up the cameras behind it.  We updated the drivers but its not the best thing to drive out there each time and hope it works better.

I found this batch, but I get the error:   "IP" was unexpected at this time??

If (!(Test-Connection 192.168.20.199 -quiet)) {
    #Write-Host "Not connected"
    Restart-Computer
}
Else {
    #Write-Host "Connected"
}

Open in new window


So i'm looking for a bat file or something, that I can schedule to run every 10 minutes.  (i know that's frequent, but I don't want the cameras not recording for longer than that.)

Any help is appreciated.
0
Comment
Question by:Knightsman
[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
5 Comments
 
LVL 3

Expert Comment

by:Gary Fuqua, CISSP
ID: 40506163
Does the computer lose IP connection?  If so, you should verify that the Ethernet Card isn't going to sleep.   Some NICs have this nuisance property.   Go to Device Manager.  Right Click on Network Card.   Select Properties, Click on Power Management Tab, Uncheck the "Allow the computer to turn off this device to save power" OptionSleep.jpg
0
 
LVL 3

Expert Comment

by:Gary Fuqua, CISSP
ID: 40506179
To answer your original question, I believe that the Test-Connection cmdlet is looking for a computer name, not an IP address.

Test-Connection <computername>

http://technet.microsoft.com/en-us/library/hh849808.aspx
0
 
LVL 7

Author Comment

by:Knightsman
ID: 40506209
Thanks for that, the first check box was checked.  I completely forgot to look there, i assumed when power mode was set to maximum it didn't set those.

I don't have another computer name the server can search for.  I guess I could use one of the cameras.  But if a camera goes down, that would then cause a big problem.  

I'd prefer for it to ping a DNS server, maybe even two.  then restart if ping fails
0
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 40506855
I'd use this VBscript:

On Error Resume Next

Dim strTarget, strPingResults
strTarget = "192.168.20.199" '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."
	WshShell.Run "shutdown /r /t 1"
End If

Open in new window

0
 
LVL 25

Expert Comment

by:Lionel MM
ID: 40506863
Other possible issues or causes could be a bad port on the switch, router the server is connected to, or the cable itself
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

739 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