windows, sysinternals, processes and disk space

Leave a comment

If you work on both unix and windows, you may find yourself wishing for unix tools like du, ps, df, proc and fuser to use on windows systems. Such tools make it easier to investigate process activity and disk utilization.

Sysinternals and vbscript to the rescue!

Sysinternals is the website run by Mark Russinovich, now at Microsoft. The utility process explorer gives you everything ps does and more! With process explorer, you can quickly find if a particular process is locking a file, for example. There’s a windows version of du that works really well. With du, you can find out what directory is consuming space very quickly. And there’s many other tools that I have yet to explore.

Lastly, the unix utility df makes it easy to see space consumed by each mountpoint from the command line. In windows, you can do this via the GUI by going to My Computer and checking there. But there’s no easy way to do this from the command line with the built-in operating system commands. Here’s a vscript file to help. To run it, place the code in a file, say get_drive_utilization.vbs. Then invoke cscript from the command prompt like this:
C:\> cscript get_drive_utilization.vbs

' Windows scripting host script in VB Script
' to list Used, Free, Total and % Free on all fixed disk drives.

Function ShowDriveList

	Dim fso, d, dc, s, n
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set dc = fso.Drives

	s = s & "DriveLetter | ShareName | DriveType | Used | Free | Total | % Free " & Chr(10) 

	For Each d in dc
		n = ""
		If d.DriveType = 3 Then
			n = d.ShareName
		ElseIf d.IsReady Then
			n = d.VolumeName
			n = "[Drive not ready]"
		End If
		Select Case d.DriveType
			Case 0: t = "Unknown"
			Case 1: t = "Removable"
			Case 2: t = "Fixed"
			Case 3: t = "Network"
			Case 4: t = "CD-ROM"
			Case 5: t = "RAM Disk"
		End Select
		If t = "Fixed" Then
			s = s & d.DriveLetter & " | " 
			free_space = FormatNumber(d.AvailableSpace/(1024*1024*1024), 2)      		
			total_space = FormatNumber(d.totalsize/(1024*1024*1024), 2)      		
			used_space = formatnumber(((d.totalsize - d.availablespace)/(1024*1024*1024)), 2)
			pct_free = formatnumber(free_space / total_space, 2)
'			s = s & n & " | " & t & " | U: " & used_space & " GB | F: " & free_space & _
'				" GB | T: " & total_space & " GB | %Free: " & pct_free & Chr(10) 
			s = s & n & " | " & t & " | " & used_space & " GB | " & free_space & _
				" GB | " & total_space & " GB | " & pct_free & Chr(10) 

		End If
	ShowDriveList = s
End Function

a = showdrivelist
wscript.stdout.write a

Flashback – Wow that was easy

Leave a comment

I got a call from a developer today with a problem. Seems an end user had inadvertently updated records incorrectly using an admin screen that facilitates bulk updates. Could I make available the data in a particular table as it was 45 minutes ago? This was Oracle 9i.

Flashback query to the rescue! After reviewing the flashback feature, I was able to do the following:
1. Create a dummy user in the target database.
2. Run exp using the flashback_time parameter to export data from about 45 minutes ago.
3. Ran imp using the newly created export dump and targeted the new user schema.
4. Ran a grant statement so that the developer could do selects on both the real table and the dummy table with old data in order to do comparisons.

Easy! Kinda like a Rachel Ray recipe…