A collection of opinions, thoughts, tricks and misc. information.
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]))
time.sleep(0.3)
command[2] = line[0]
time.sleep(1)