home | login | register | DMCA | contacts | help | donate |      

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


my bookshelf | genres | recommend | rating of books | rating of authors | reviews | new | | collections | | | add



8.7.3.1. ...sending log messages to a program?

The standard Fedora syslog program does not support output to a program such as a mailer. However, you can easily write a script that reads a logfile using the tail command and outputs new log entries to a program.

This example emails log messages to a pager or cell phone text service:

#!/bin/bash


DESTINATION= [email protected]


tail -0f /var/log/messages|

while read LINE

do

echo $LINE|

mail $DESTINATION

done


To use this script, place it in the file / usr/local/bin/log-mail and add read and execute permissions:

# chmod u+rx /usr/local/bin/log-mail

# log-mail

You may want to use this script with a lower-volume logfile than /var/log/messages, especially if you pay for each pager message.

To filter messages by content, place a grep command between the tail and while lines in the script.

You can also have log output read to you over the system's speakers:

#!/bin/bash


logger -t log-speak "Starting log reading."

sleep 0.3


tail -1f /var/log/messages|

while read LINE

do

# The sed expressions remove the date/time and PIDs

# from messages to shorten the text.

echo $LINE|

sed -e "s/^.\{17\}[^ ]*//"-e "s/\[.*\]//g"|

festival --tts

done


8.7.2. How Does It Work? | Fedora Linux | 8.7.3.2. ...outputting to a named pipe?