Archive for March, 2007

Mr. Fix-It-All

Wednesday, March 28th, 2007

Why do things have to break? Particularily, why is water so revengeful with me so that it leaks where it’s not supposed to, and does not flow where it’s supposed to? Why do faucets play tricks on me?

It’s the third time in a few weeks when I’m having serious problems with the plumbing. And, every time this happens, it’s right before I’ve made plans for something, which I must cancel to attend to these emergencies.

Considering the hours I work, I can’t get a plumber to do the work for me. I’d have to stay half a day at home to watch him work. And then, I’d be pissed to no end looking at the careless job he’s done.

So, I’m Mr. Fix-It-All. Nothing is too difficult to repair, and to do it right. But it’s aggravating to have to do these things at the least desirable moment.

The toilet’s flushing mechanism broke, right before having guests for the New Year’s party. In the next two months I ended up buying 4 different mechanisms until I found one that a) works, and b) doesn’t break again after the third use.

Some two weeks ago, the toilet’s faucet started dripping, hidden away, until I noticed the big, wet spot on the wall of the staircase, created by infiltrated water. I didn’t have a wrench big enough, so there I go to the store to buy tools, rubber washers, new faucet, then fix the problem late at night when I got back from work.

Last weekend, the kitchen sink’s faucet decided to go on a permanent strike. It was such a nice day and I made plans to go out and play with my camera. Instead, I replaced the faucet, washers, cleaned the mess under the sink, and the day was already gone.

Today, as I open the front door, I hear a hiss inside that gives me cold chills. Hoping that it’s not a gas pipe, I step in and… splat into a puddle of water stretching all the way from the entrance to the bathroom. Water is spraying out of the wall, right where the sink’s faucet comes out. I have no idea if it’s a cracked pipe, an old rubber seal or what else, because… I don’t have a wrench big enough for THIS one. I had plans to attend the opening of a car tuning show tomorrow; looks like I’ll attend the line at the do-it-yourself shop again.

Keep fingers crossed for me, I hope I don’t have to chisel my way through the wall to replace a water pipe.

[edit] Whew, no chiseling required, but a pipe screwed into another broke off and left a piece of metal tightly screwed inside. It took a while to get it out, but it’s done. Everything is fixed now, I have running water again!

Blocking abusive spider from AllResearch

Saturday, March 17th, 2007

Checking my blog’s visitor statistics, I noticed one particular IP address standing out from the crowd. It accumulated more hits than second, third and fourth top visitors together, and ate up an impressive amount of traffic. A brief check revealed that the IP address resolves to rss.allresearch.com.

Who is AllResearch? It is a company that provides statistics for the web to its paying customers. One of its specialties is to find out how many people are talking about certain brands or products online and report these to their customers. Mention Coca-Cola in your blog and you’ll be a part of AllResearch’s statistics sent to the company. Another activity is to provide “clippings” from various blog touching a certain keyword. Your post on Coca-Cola will be fed to customers who want to read what’s new on the web about this keyword. This is achieved through a subscription-based site, webclipping.com — another product of AllResearch. Basically, your blog is the source of revenue for AllResearch.

In order to pull this information, AllResearch sends “spiders” (automatic programs) to index the millions of blogs out there and find new information they could use. Google, Yahoo and MSN do this as well, with one difference: AllResearch’s spiders flood your blog with requests, as often as once per hour. Search engines’ spiders are more considerate and more intelligent, they only check your site for changes and index it when there’s new information. AllResearch disregards this and re-reads on each visit everything you’ve posted. This makes your site’s traffic skyrocket, and you’re most likely paying for the extra traffic.

In short, AllResearch piggybacks the blogosphere to make a nice buck, with a complete indifference to limiting the unnecessary load they put on others’ sites. This, in my opinion, is abusive, and I’m not the only one noticing it. Daniel Bowen at GeekRant went through the same experience in February 2005. Larry Snider had a conversation with AllResearch in December 2004. Google AllResearch and find out more.

So today I blocked their spider’s IP from being able to access my blog. This is simply done with a “deny” rule added to the .htaccess file of my site. My web host’s Apache server checks this file for each visit and, from now on, will not respond to any requests from the IP I’ve blacklisted.

This is the second time I’ve encountered abusive behaviour towards my blog. The first time was some time ago, when someone installed Google Desktop Search on their computer, and that application was indexing my blog even more often than once an hour. My site’s traffic exceeded in a few days the total traffic in several months. I’m not the kind of guy who will tolerate such an abuse, even of an automated computer system.

Farewell, AllResearch, you’re not going to extend your business through my blog’s content any longer. May you and the disgusting likes of you miserably disappear in oblivion.

Catching up

Friday, March 16th, 2007

It was about time I spent some time updating WordPress here. Versions came and passed, all urging users to update to fix some known flaws, but I just couldn’t get around to do it. Fortunately, it seems that nobody reads this blog anymore, and no “hackers” tried to exploit those vulnerabilities. Whew.

I sort of picked up a few things about the world around me. Did y’all know Hillary is running for presidency? ;) In the past few months, I have been completely oblivious to TV news, newspapers, magazines, radio… I loathe politics, scandal-focused media disgusts me to no end, social abnormalities went past boring a long time ago, news on the economy are incomplete and out of context, and positive news are more scarce than misprints. Why bother?

I’m catching up with my hobby as well: two lens for my digital SLR camera are on their way. They pretty much emptied my pockets, and all I can hope is that they will live up to my expectations. They couldn’t arrive at a better time for going out to take photos: it’s spring — flowers are blooming, the sun tickles the skin with warmth, parks are full of people and kids having a good time, ladies’ skirts grew shorter…

Scheduled automatic hard drive defragmentation for Windows Server 2003

Friday, March 16th, 2007

The problem

Suppose you are the administrator of one or more servers running Windows Server 2003. You probably have a schedule of maintenance tasks you perform on a periodic basis, such as checking system logs, installing software updates, maintaining security policies, cleaning up users’ files and defragmenting the hard drives.

For the last activity, you may have opted for a third party solution such as O&O Software’s Defrag for servers. I love and trust this solution — it’s a powerful and flexible tool specialized on defragmenting drives, making this recurring activity a breeze to manage.

But what if you’re in a corporate environment that, for several reasons, will stick to the Windows built-in defragmenter? Would you spend several hours a week attending to manually defragmenting drives and be happy with it? That’s silly.

Fortunately, unlike the Windows XP counterpart, the defragmenter application in Windows Server 2003 can be started from a batch script, so you can automatize the defragmentation activity. But things get a little more complicated if you have several partitions you want to defragment or if you want to perform more advanced tasks.

The needs

Here’s what I wanted:

  • Defragment all drives and partitions in the system sequentially (one after another).
  • Prevent multiple instances of the defragmenter from running in parallel.
  • Defragment only if there is sufficient free disk space for the defrag to work optimally (minimum 15% of disk space free).
  • Defragment only if the defragmenter recommends it, so it doesn’t run on drives with a 2% fragmentation.
  • Log the activity somewhere — I chose the system log for it, since I’m already checking it at least once a week, but this can be done easily in a text file.
  • Prepare for possible errors and log them.

I studied several scripts for automatic defragmentation on the web and built my own, to match my needs. Credit and thanks goes to everyone else who has attempted this in the past.

The script

' Unattended defragmentation script for Windows Server 2003
' Checks all hard drives and defragments them as necessary
' Create a BAT file with the following command:
'     CSCRIPT AutoDefrag.vbs //B
' Call the BAT file from Scheduled Task, run as Administrator or another user with rights for defragmenting disk
Const EVENT_SUCCESS = 0
Const EVENT_ERROR = 1
Const EVENT_WARNING = 2
Const EVENT_INFORMATION = 4
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("Wscript.Shell")
' Check if another instance of Windows Defrag is already running
Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = ' Dfrgntfs.exe'")
If colProcesses.Count = 0 Then
	' No other instance found
	' Write information message in the system log
	objShell.LogEvent EVENT_INFORMATION, "Starting unattended disk defragmentation."
	' Find all hard drives
	Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume where DriveType = 3")
	For Each objVolume in colVolumes
		' Analyze drive, check if it is recommended to defragment it
		errResult = objVolume.DefragAnalysis(blnRecommended, objReport)
		' Check if the operation completed without errors
		If errResult = 0 Then
			' Fragmentation check completed without errors
			' Check if there is sufficient free space on disk for defragmentation (minimum 15%)
			If (objReport.FreeSpacePercent < 15 ) Then
				' Drive doesn't have enough free space for an efficient defragmentation
				' Write error message in the system log
				objShell.LogEvent EVENT_WARNING, "Drive " & objVolume.Name & " is almost full and cannot be defragmented! Drive is " & objReport.FreeSpacePercent & "% free."
			Else
				' There is enough free space
				' Is it is recommended to defragment current drive?
				If (blnRecommended) Then
					' Yes, current drive should be defragmented
					' Write information message in the system log
					objShell.LogEvent EVENT_INFORMATION, "Drive " & objVolume.Name & " should be defragmented: " & objReport.TotalPercentFragmentation & "% total fragmentation, " & objReport.FilePercentFragmentation & "% file fragmentation. Drive is " & objReport.FreeSpacePercent & "% free."
					' Begin defragmentation
					errResult = objVolume.Defrag()
					' Check if defragmentation completed without errors
					If errResult = 0 Then
						' No errors, defragmentation is complete
						' Write information message in the system log
						objShell.LogEvent EVENT_SUCCESS, "Drive " & objVolume.Name & " successfully defragmented."
					Else
						' Error encountered
						' Write error message in the system log
						objShell.LogEvent EVENT_SUCCESS, "Drive " & objVolume.Name & " could not be defragmented. Error code: " & errResult & "."
						Err.Clear
					End If
				Else
					' No, current drive doesn't need to be defragmented
					' Write information message in the system log
					objShell.LogEvent EVENT_SUCCESS, "Drive " & objVolume.Name & " does not need to be defragmented: " & objReport.TotalPercentFragmentation & "% total fragmentation, " & objReport.FilePercentFragmentation & "% file fragmentation. Drive is " & objReport.FreeSpacePercent & "% free."
				End If
			End If
		Else
			' Fragmentation check generated an error
			' Write error message in the system log
			objShell.LogEvent EVENT_WARNING, "Drive " & objVolume.Name & " could not be analyzed. Error code: " & errResult & "."
		End If
	Next
	' Finished checking and defragmenting all hard drives in the system
	' Write information message in the system log
	objShell.LogEvent EVENT_INFORMATION, "Unattended disk defragmentation is complete."
Else
	' Another instance of Windows Defrag already running
	' Write error message in the system log
	objShell.LogEvent EVENT_ERROR, "Unattended disk defragmentation is unable to start: another instance of NTFS Defrag is already running."
End If

How to use this?

  1. Copy and paste this text in Notepad, save the text file as autodefrag.vbs in a folder on your Windows Server 2003 machine.
  2. In another Notepad window, enter the command: cscript autodefrag.vbs //B and save it as autodefrag.bat in the same folder with autodefrag.vbs .
  3. Create a new scheduled task that runs autodefrag.bat whenever you want. Make sure you run this under an account with administrative priviledges.

Tips

  • Schedule automatic defragmentation at a time when it doesn’t conflict with other disk-intensive activities, such as file transfers, database backups, file archival, tape backups, other maintenance.
  • Check logs to make sure the defragmentation ended without errors.
  • If a partition is almost full, free up some space and defragment it manually.
  • Check if partitions that were skipped by the automatic defragmenter really do not need to be defragmented.
  • For optimum performance, prepare your drives before automatic defragmentation commences — delete temporary files, archive logs and other files.
  • Augment this script to write details of its actions in a separate log file you can back up or send by e-mail, as needed. On request, I could prepare a version which also uses text files for logs.

If you find this script useful, I’d really like to hear your experiences with it.