Submitted By: Doug Hilderbrand
Uses the Windows Resource Kit utility Uptime.exe to query a list of servers and retrieve information about abnormal shutdowns, blue screens, and other events. Also requires a Windows implementation of Cut.
@echo off :: requires ntresource kit util uptime.exe and a Windows implementation of cut in the system path :: also requires a list or lists of Windows servers to poll. setlocal set daysback=30 if Not "%1"=="" set daysback=%1 set tempfile=%temp%\uptimes.tmp if not "%2"=="" set daysback=30 & call :Headings & goto :list call :Headings for /F "eol=#" %%i in (c:\batch\Servers.txt) do uptime /p:%daysback% \\%%i > %tempfile% & call :filter %%i goto :end :list for %%i in (%*) do uptime /p:30 \\%%i > %tempfile% & call :filter %%i goto :end :filter set percent= set reboots= set daysup= set MTBR= set Note= set lastboot= set AbShuts=0 set BlueS=0 set Boots=0 set Shuts=0 for /F %%i in ('findstr Availability %tempfile% ^| cut -d":" -f2 ^| cut -d" " -f2') do set percent=%%i for /F %%i in ('findstr /c:"Total Reboots" %tempfile% ^| cut -d":" -f2') do set reboots=%%i for /f %%i in ('findstr /c:"Current System" %tempfile% ^| cut -d" " -f4') do set daysup=%%i for /F %%i in ('findstr Mean %tempfile% ^| cut -d":" -f2 ^| cut -d"d" -f1') do set MTBR=%%i for /F %%i in ('findstr earliest %tempfile%') do set Note=* for /F %%i in ('findstr /c:"Bluescreen " %tempfile%') do set /a BlueS=BlueS + 1 for /f %%i in ('findstr Abnormal %tempfile%') do set /a AbShuts=Abshuts + 1 for /f %%i in ('findstr Boot %tempfile%') do set /a Boots=Boots + 1 & set lastboot=%%i for /f %%i in ('findstr /c:" Shutdown" %tempfile%') do set /a Shuts=Shuts + 1 set server=%1 set server=x %server% set server=%server:~-15% if "%Note%"=="*" set percent= set percent=x %percent% set percent=%percent:~-9% if "%reboots%"=="0" set reboots= set reboots=x %reboots% set reboots=%reboots:~-3% if "%boots%"=="0" set boots= set boots=x %boots% set boots=%boots:~-3% set MTBR=x %MTBR% set MTBR=%MTBR:~-7% if "%Blues%"=="0" set Blues= set Blues=x %Blues% set Blues=%Blues:~-3% if "%AbShuts%"=="0" set AbShuts= set AbShuts=x %AbShuts% set AbShuts=%AbShuts:~-3% set /a diff=%boots% - %shuts% if %diff% EQU 0 set Shuts= set Shuts=x %Shuts% set Shuts=%Shuts:~-3% set daysup=x %daysup% set daysup=%daysup:~-3% echo %server%%Note% %daysup% %percent% %boots% %MTBR% %Blues% %AbShuts% %shuts% goto :EOF :Headings echo %daysback% day uptime stats %date% echo. echo ^|Days^| ^| ^| MTBR ^| Blue ^| Abnormal^|Shutdowns echo Server ^| up ^| Uptime ^|Boots^|in days^|Screens^|Shutdowns^| Note ** echo ===================================================================== goto :EOF :end echo. echo * = Insufficient data in the event log to calculate system availability. echo. echo ** = Number of shutdown events not equal to number of boot events
@echo off :: requires ntresource kit util uptime.exe and a Windows implementation of cut in the system path :: also requires a list or lists of Windows servers to poll. setlocal set daysback=30 if Not "%1"=="" set daysback=%1 set tempfile=%temp%\uptimes.tmp if not "%2"=="" set daysback=30 & call :Headings & goto :list call :Headings for /F "eol=#" %%i in (c:\batch\Servers.txt) do uptime /p:%daysback% \\%%i > %tempfile% & call :filter %%i goto :end :list for %%i in (%*) do uptime /p:30 \\%%i > %tempfile% & call :filter %%i goto :end :filter set percent= set reboots= set daysup= set MTBR= set Note= set lastboot= set AbShuts=0 set BlueS=0 set Boots=0 set Shuts=0 for /F %%i in ('findstr Availability %tempfile% ^| cut -d":" -f2 ^| cut -d" " -f2') do set percent=%%i for /F %%i in ('findstr /c:"Total Reboots" %tempfile% ^| cut -d":" -f2') do set reboots=%%i for /f %%i in ('findstr /c:"Current System" %tempfile% ^| cut -d" " -f4') do set daysup=%%i for /F %%i in ('findstr Mean %tempfile% ^| cut -d":" -f2 ^| cut -d"d" -f1') do set MTBR=%%i for /F %%i in ('findstr earliest %tempfile%') do set Note=* for /F %%i in ('findstr /c:"Bluescreen " %tempfile%') do set /a BlueS=BlueS + 1 for /f %%i in ('findstr Abnormal %tempfile%') do set /a AbShuts=Abshuts + 1 for /f %%i in ('findstr Boot %tempfile%') do set /a Boots=Boots + 1 & set lastboot=%%i for /f %%i in ('findstr /c:" Shutdown" %tempfile%') do set /a Shuts=Shuts + 1 set server=%1 set server=x %server% set server=%server:~-15% if "%Note%"=="*" set percent= set percent=x %percent% set percent=%percent:~-9% if "%reboots%"=="0" set reboots= set reboots=x %reboots% set reboots=%reboots:~-3% if "%boots%"=="0" set boots= set boots=x %boots% set boots=%boots:~-3% set MTBR=x %MTBR% set MTBR=%MTBR:~-7% if "%Blues%"=="0" set Blues= set Blues=x %Blues% set Blues=%Blues:~-3% if "%AbShuts%"=="0" set AbShuts= set AbShuts=x %AbShuts% set AbShuts=%AbShuts:~-3% set /a diff=%boots% - %shuts% if %diff% EQU 0 set Shuts= set Shuts=x %Shuts% set Shuts=%Shuts:~-3% set daysup=x %daysup% set daysup=%daysup:~-3% echo %server%%Note% %daysup% %percent% %boots% %MTBR% %Blues% %AbShuts% %shuts% goto :EOF :Headings echo %daysback% day uptime stats %date% echo. echo ^|Days^| ^| ^| MTBR ^| Blue ^| Abnormal^|Shutdowns echo Server ^| up ^| Uptime ^|Boots^|in days^|Screens^|Shutdowns^| Note ** echo ===================================================================== goto :EOF :end echo. echo * = Insufficient data in the event log to calculate system availability. echo. echo ** = Number of shutdown events not equal to number of boot events