{"id":154,"date":"2008-12-15T01:32:48","date_gmt":"2008-12-15T06:32:48","guid":{"rendered":"http:\/\/yourlinuxguy.com\/?p=154"},"modified":"2008-12-01T16:03:54","modified_gmt":"2008-12-01T21:03:54","slug":"how-can-i-automatically-reboot-a-windows-machine-that-lost-connectivity","status":"publish","type":"post","link":"https:\/\/yourLinuxGuy.com\/?p=154","title":{"rendered":"How can I automatically reboot a windows machine that lost connectivity?"},"content":{"rendered":"<p>Yep, it&#8217;s a windows question again folks!<\/p>\n<p>A while back, I wrote a cute little batch script for a Win2k3 server that is a VMWare guest, that kept losing connectivity to the VMNetwork. The guest itself was up and fine, however it just could not communicate with anything until it was rebooted.<\/p>\n<p>So, I wrote the script to detect when it could no longer reach its own gateway (or the VM host for that matter), and would reboot itself as gracefully as possible. I configured a &#8220;task&#8221; to launch the script at boot, and removed the loop protection and stuff from the task properties (since it *is* a loop script, after all).<\/p>\n<p>I got asked about this script enough that it warranted its own post on my blog. And, I&#8217;m just going to paste the script right here into the post itself (at bottom) rather than as an attachment. I hope that works for you&#8230;<\/p>\n<p>Enjoy!<br \/>\nHere&#8217;s the script:<\/p>\n<pre><code><span style=\"font-size: xx-small;\">@ECHO OFF\r\n\r\nrem Run this script once, at start-up, and it\r\nrem will loop itself forever. Hopefully.\r\n\r\nrem The dash-n option in the ping controls how\r\nrem long each loop is, as it does one ping per\r\nrem second. Of course you should set the host\r\nrem that you are pinging to something like the\r\nrem default gateway of the server.\r\n\r\nrem If *ANY* of the pings get replies, then\r\nrem the return code is zero, and the destination\r\nrem host is considered to be up.\r\n\r\nrem If *NO* ping replies come back for and entire\r\nrem loop, then the box will reboot. This means\r\nrem that communication could be lost for *almost*\r\nrem two complete loops in order to reboot. To be\r\nrem specific, it could be as quick as:\r\nrem - one loop plus one ping\r\nrem ...or as long as:\r\nrem - two loops minus one ping\r\n\r\n:LOOP\r\nping -n 10 192.168.1.1\r\n\r\nIF NOT ERRORLEVEL 1 GOTO LOOP\r\nIF ERRORLEVEL 1 GOTO REBOOT\r\n\r\n:REBOOT\r\necho We will reboot in 5 seconds!\r\nrem For windows xp, the following command should\r\nrem use dashes (-) for all the flags. For windows\r\nrem server 2003, use forward slashes for the flags.\r\nshutdown \/r \/f \/t 5 \/c \"Pings failed. Rebooting.\" \/d 5:20\r\n<\/span><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Yep, it&#8217;s a windows question again folks! A while back, I wrote a cute little batch script for a Win2k3 server that is a VMWare guest, that kept losing connectivity to the VMNetwork. The guest itself was up and fine,&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/yourLinuxGuy.com\/?p=154\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,20],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-introductory","category-windowsgeneral"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnjn1-2u","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154"}],"version-history":[{"count":6,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":161,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/161"}],"wp:attachment":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}