This site is now 100% read-only, and retired.

XML Logo

Posted by PJ_at_Belzabar_Software on Thu 6 Sep 2007 at 09:36
Tags: none.
I just figured out a lazy (short) and robust way to define "yesterday". I think it is pretty cool. Of course I'm probably reinventing the wheel, but I thought I'd gloat about it here anyway.

Imagine you have a log file you want to grep through daily to look at what went on yesterday. The log file is timestamped with the date, and is in a human-readable type of format (eg starting with: Sep 5 2007 18:53). How do you grep through yesterday's logs in an automated way without putting in yesterday's date manually? And keeping it simple?

The problem is that yesterday isn't defined with simple code (think of the rollover for a month or year etc). Which is why we have a zillion perl date handling modules.

But we can avoid worrying about it. The principle is to define yesterday using something like this in bash:

yesterday=`perl -e '$string = localtime($ARGV[0]-86400); print "$string"' \`date +%s\``

(the way this works is that bash's date gives today's date. This is output in the seconds-since-1970 format. This output is the argument used by perl, and has 86400 seconds (1 day) chopped off it. The string that perl then prints out is a human readable timestamp format (eg Wed Sep 5 13:59:57 2007) and this is what becomes the $yesterday variable.)

(Oh, yeah, and you may want to add a

| cut -b5-10

or something like that before the last backtick if you want to handle only some fields).

Then you grep using $yesterday as your pattern through the log file.

The reason I think this is cool is because of the way you dump the problem onto bash date and perl, which handle dates robustly, so the problem is no longer yours.

Well, I thought it was frightfully neat. Now I'm off to pat my back.

PJ

 

Posted by PJ_at_Belzabar_Software on Tue 13 Feb 2007 at 09:10
Tags: none.
http://goodbye-microsoft.com/ sounds interesting. Too bad I don't have a MS box to try this out on.

Ideally we shouldn't have the MS tax in the first place.

PJ

 

Posted by PJ_at_Belzabar_Software on Wed 10 Jan 2007 at 05:42
Tags: none.
I'm working on a HollywoodDesktop theme. This has the computer behaving like in the movies.

For a start, I've decided I need an utterly useless "Access Granted" message. Conversely, of course, I'll need the "Access Denied" message as well for the obligatory first few times that I get it wrong while I do my decrypting letter by letter with the widget that I've gratuitously plugged into the system network.

In Debian:

the Access Denied comes up in big red letters in xdm if you replace the xlogin*fail: line in /etc/X11/Xresources.

For the Access Granted I've just put in:

xmessage -timeout 3 -buttons "" -center "ACCESS GRANTED" &

in the first line of my xsession. gdm, kdm users will probably have something similar.

Cool. Next on my agenda:

beeps as I type in letters, 70s style.

If I don't continue this thread, then you may take it that I've been successful on the beep front, and that my co-workers have formed a howling irate mob and lynched me.

PJ