Tuesday, 28 September 2004

Hardlinks 101

It was late, I was tired and needed to keep more than 2 rotated logs of Resin's stderr file. By default it only saves 3: stderr.log (the one it is writing to), stderr.log.1 and stderr.log.2 (the last two most recent copies).

I didn't want to dig through all the documentation and I still don't want to. In fact, the solution I found is still in place. I must confess, the solution wasn't mine, but my from a work colleague of mine, Dom. He is the kind of guy who comes up with the weirdest stuff using named pipes, hardlinks and whatever they stuffed in his head on university classes.

Anyway, he suggested I kept count of the number of hardlinks to the file. As you may well know, the EXT3 filesystem keeps the number of references to a file, and when this number equals 0, the space is marked as free (or, if you prefer, the file is "deleted" - the data is still there, and theoretically you can recover it, but only the gurus at bugtraq know how to do it).

So I came up with this little script, that I believe sums up pretty well the elegance and simplicity of *nix.





#!/bin/bash

LOGDIR='/usr/java/resin/log'
PH='stderr.placeholder'

cd $LOGDIR

if [ ! -r $PH ]; then
echo $PH not found - trying to create link
if [ -r "stderr.log.2" ]; then
ln stderr.log.2 $PH
if [ $? -eq 1 ]; then
echo error trying to create hardlink - bailing out
exit 1

fi
else

echo stderr.log.2 does not exist yet - bailing out
exit 0
fi
fi

HLCNT=`stat -c %h stderr.log.2`
if [ $HLCNT -eq 1 ]; then
cat $PH >> stderr.$(date +%Y%m%d)
rm -f $PH
ln stderr.log.2 $PH
fi


The first big block of code just checks to see if the placeholder for the stderr.log.2 file already exists. If it then tries to create it.

The real magic happens from HLCNT and beyond. This variable will hold the results of the stat comand, enclosed in ``s, which is the number of hardlinks to the stderr.log.2 file data. This is normally 2: one for the hardlink the script created (and pointed by the file stderr.placeholder) and the other is for the stderr.log.2 file itseld.

When resin rotates the logfile, the hardlink count drops to 1, because now only stderr.placeholder points to the data. That happening, the script then concatenates the file contents to another file, which will hold all the data for the day. VoilĂ . Thanks to my buddy Dom I could go home without reading wads of documentation. :)

Friday, 17 September 2004

winmail.dat

The dreaded, hated attachment:



Fear no more! Project TNEF saves the day.

Can someone please explain me why the fuck MS needs to "embrace and extend" even a simple thing as email attachment. Instead of using mime to attach a file as everyone else, MS uses mime to attach a file in a proprietary format. That makes me a sad, sad panda.

Thursday, 16 September 2004

Over 20 Years of High-Tech Marketing Disasters

After reading Chapman's In Search of Stupidity, I suddenly stopped feeling bad for Amazon (not that I really ever did). I was looking at book a friend recommended (yes, I linked to B&N, yes I can hold a grudge) and tried to check out a sample of the book. I was awarded with this one:




They are "please to offer"? What they need is a new spin doctor because that one didn't work on me.

Let me get this straight. They want my credit card number so I can look at a book? What is this, some sort of ransom? of show me yours and I'll show you mine? sheesh. I guess it's pretty useless, but I left a comment anyways:




The typos were made in the heat of the moment - I hope I don't get a grammar-nazi to read my message.

Thursday, 2 September 2004

pinfo date

I was going to check the manual for "date (1)" to write a simple script and I'm gifted with this beautiful quote:

Gotta love open-source software. The comments on the linux kernel alone have appeased my boredom many times.

Wednesday, 1 September 2004

MSN on Gaim

So I installed MSN on my Win XP VMWare machine because gaim kept crashing. Now MSN crashes on Windows. Cool, eh? Guess I'll just stick with ICQ.

Update: MS says this issue has been fixed on SP2. Gonna give it a try, but somehow I get the feeling SP2 will breed a few posts of its own.