Recipe2.16.Viewing System Uptime


Recipe 2.16. Viewing System Uptime

Problem

You want to find out how long a server has been running since the last restart.

Solution

Using a command-line interface

All three of the following commands display the system uptime:

> psinfo \\<ServerName> | findstr Uptime > srvinfo \\<ServerName> | findstr /c:"Up Time" > systeminfo /s <ServerName> | findstr /c:"Up Time"

Using VBScript
' This code prints system uptime for a host. ' ------ SCRIPT CONFIGURATION ------ strComputer = "."   ' e.g., rallen-srv01 ' ------ END CONFIGURATION --------- set objWMIDateTime = CreateObject("WbemScripting.SWbemDateTime") set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colOS = objWMI.InstancesOf("Win32_OperatingSystem") for each objOS in colOS    objWMIDateTime.Value = objOS.LastBootUpTime    Wscript.Echo "System Up Time: " & objWMIDateTime.GetVarDate next

Discussion

In the early days of Windows NT 3.51 and 4.0, it wasn't uncommon for servers to reboot or need to be rebooted on a regular basis. Applications were not as well behaved as they are today and the operating system wasn't as stable. This changed with Windows 2000, when unexpected failures became much less common. But there were still a lot of hotfixes and patches to install on a regular basis, most of which required reboots. Hopefully Windows Server 2003 will continue the upward trend in availability and further reduce the number of reboots that are required.

It is a good idea to pay attention to the uptime on your servers to make sure their availability jives with what you think it should be. Perhaps a server rebooted due to a blue screen or even worse, because another administrator (or attacker!) did something they shouldn't have. Looking at system uptime is the poor man's availability monitor. You may even want to create a script that runs at system startup on your servers, which can serve as a notification mechanism anytime your servers reboot.



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net