in reply to POE::FollowTail and xterm

Hi

Why don't you try a different approach, start a Tk application and use the POE::Loop::Tk or "better" POE::Loop::Gtk. See Gtk example in http://poe.perl.org/?POE_Cookbook/Gtk2_Counter

Replies are listed 'Best First'.
Re^2: POE::FollowTail and xterm
by wishartz (Beadle) on Apr 17, 2008 at 10:33 UTC
    Thanks for your help. I wasn't absolutely clear on what I wanted to do. The problem is this program will be for some operators at work and they will be informed when there is a new message for them to take note of. The old script that we use at work was written in kornshell and is run by a crontab every two minutes. What it does is, make a copy of the log file and then compare another version of the log file two minutes later and report if there are any new messages and bring them up in a new xterm window. There is a new xterm window for each log file every two minutes. The reason, I am changing the script is it is not ideal, it's a bit of an overhead to compare the files every two mins. With POE::followtail I don't need to run a cron I could just keep it running and informing on new messages. I could also choose to exclude certain messages as well. I didn't really want to run two scripts to redirect the output to an xterm window, is there anyway of redirecting the output to a new xterm console in the perl script? Thanks
      Using the following code, is there any way that I can make it open a new xterm for each log file?
      my %logs_to_watch = ( cron => "/var/log/cron", mail => "/var/log/maillog", ppp => "/var/log/ppp.log", httpd => "/var/log/httpd-access.log", msg => "/var/log/messages", ); # Start a session to watch the logs. POE::Session->create ( inline_states => { _start => \&begin_watchers, # Handle records from each log differently. cron_record => \&cron_got_record, mail_record => \&mail_got_record, ppp_record => \&ppp_got_record, httpd_record => \&httpd_got_record, msg_record => \&msg_got_record, # Handle log resets and errors the same way for each file. log_reset => \&generic_log_reset, log_error => \&generic_log_error, } ); =for cookbook Start log watchers. Scans the hash of %logs_to_watch, creating a new FollowTail wheel to watch each. Each watcher emits an event based on its key in %logs_to_watch. Those events are handled by functions that will parse, filter, and if necessary display information about the records. For example, cron is the key for "/var/log/cron". The cron log watcher will emit a "cron_record" event whenever that file extends. The POE::Session->create() call above associates the "cron_record" event with the cron_got_record() function later on. =cut sub begin_watchers { my $heap = $_[HEAP]; while ( my ( $service, $log_file ) = each %logs_to_watch ) { my $log_watcher = POE::Wheel::FollowTail->new ( Filename => $log_file, InputEvent => $service . "_record", ResetEvent => "log_reset", ErrorEvent => "log_error", ); $heap->{services}->{ $log_watcher->ID } = $service; $heap->{watchers}->{ $log_watcher->ID } = $log_watcher; } }