I require some assistance with the following:
I am working on a script that detects if the CPU usage is high on the server, then stop/starts the specific offending service (attempts to at least)
Can you advise what I need to add to the script in order to restart the server if a particular (or offending service) doesn't start correctly?
This is what I've got thus far
REM Craig Paulsen - Restart WDS Service Beta 1.1
SET /A "MAXUSAGE=60"
SET /A "INTERVAL=300"
For /F %%P in ('wmic cpu get loadpercentage ^| FINDSTR "[0-9]"') do (
IF %%P GTR %MAXUSAGE% (
Echo [%TIME:~0,8%] CPU Usage: %%P%% Reached the limit: %MAXUSAGE%%%
Echo Stopping %SERVICE% ...
SC STOP "%SERVICE%" 1>NUL
timeout /t 1500
SC START "%SERVICE%" 1>NUL
Echo Attempt %SERVICE% restart.
) ELSE (
Echo [%TIME:~0,8%] CPU Usage: %%P%%
Ping -n %INTERVAL% Localhost >NUL
Your help will be most appreciated.