Tidbits @ Kassemi

A collection of opinions, thoughts, tricks and misc. information.

Tuesday, December 20, 2005


Linux log monitor

Okay, so I've been thinking for a while how nice it would be to have a little message pop up on my screen whenever something was added to one of my logs, and I didn't really want to work on something I'd get rid of quickly, so I never worked on the program. Today though I learned about xmessage (Which shows I've still got a long way to go with this whole linux thing :)). I threw together a quick python script that monitors logs for you:

#! /usr/bin/env python

""" A very simple monitor, using xmessage to display information about an update to any file... """

import os, time

# Will check each item, takes the form of 'command to read log, identifier, and last line read (leave empty)...

reader = [
['dmesg', 'System Logs', ''],
['cat /var/log/apache/error_log', 'Apache Error', ''],
['cat /var/log/apache/access_log', 'Apache', '']

while 1:
for command in reader:
read = os.popen("%s | tail -n 1" % command[0])
line = read.readlines()
if line[0] <> command[2]:
if command[2] <> "":
os.popen("echo \"%s: %s\" | xmessage -center -file - -timeout 3" % (command[1], line[0]))
command[2] = line[0]

Comments: Post a Comment

<< Home


August 2005   September 2005   October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006  

This page is powered by Blogger. Isn't yours?