I am using (trying) a batch file to initiate a reboot when connectivity to a switch is lost. what I need is to have the PC ping the IP address of the switch and when the connection has been lost, the PC reboots. I have found a few sources and am using pieces of multiple codes to achieve this. The script below works however I also would like to have a couple additional features determined.
- PC reboots only after 3 failed attempts
- PC pings the IP checking for active connection every 5 minutes
- Batch runs on startup
- Email is sent after connection is re-established to notify me that there was a loss in connection.
I would prefer to have the batch file performing all the above tasks but have also found that I may only accomplish #2 & #3 by adding a scheduled task in Windows.
Below is the current script I am using. Any information is appreciated.
@echo
ECHO Checking connection, please hang tight for a second...
PING -n 4 216|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :TRYAGAIN
:TRYAGAIN
ECHO FAILURE!
ECHO That failed NOT good. lets try again...
@echo
PING -n 4 216|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS2
IF ERRORLEVEL 1 goto :FAILURE
:SUCCESS
ECHO You have an active connection.
pause
goto :END
:SUCCESS2
ECHO network connectivity exists but there may be an issue still
goto :END
:FAILURE
ECHO You do not have an active connection.
pause
ECHO Restarting PC in 60 seconds. Run SHUTDOWN -a to abort.
pause
SHUTDOWN -r -t 60 -f
:END
Sources: (http://www.cam-it.org/index.php?topic=2786.0) (http://www.instructables.com/id/Shutdown-restart-or-hibernate-your-computer-on-a/)