I understand how to configure the syslogd.conf to put the logs direct
to a named pipe . Now i want to write my perl script , but i have
really problems using named pipes .
I created named pipe manually (mkfifo pipe ) , change it permissions
so that the script can read and write from it ( 0777 )
To make it really secure, make the owner 'root' and make the permissions
600 (-rw-------).
You don't what *anyone* to have the ability to read/write to the FIFO -
because that would open a potential "hole" in your system and
you don't wwant that
#!/usr/bin/perl
$fifo_name = "./fifo" ;
while(1){
open(FIFO ,"> $fifo_name");
$error = <FIFO> ;
if($error){
chomp($error);
print "Error: $error\n";
}
}
This is what I have used. I used IO::File versus 'open'.
--read script --
#!/usr/bin/perl -w
use strict;
use IO::File;
$SIG{__WARN__} = $SIG{__DIE__} = sub { print "Opps\n$_[0]\n$!\n"; exit; };
$SIG{ALRM} = $SIG{INT} =
sub { undef $fh; print "Caught a signal - Terminating\n"; exit; };
my $fh = new IO::File "/tmp/myfifo";
while (1) {
while ( my $line = $fh->getline ) {
print "FIFO: $line";
}
}
exit;
-----------------
--write script --
#!/usr/bin/perl -w
$SIG{__DIE__} = $SIG{__WARN__} =
sub { print "Dying\n$!\n$@\n ... exiting\n"; exit; };
$SIG{INT} = $SIG{TERM} = sub { print "Caught a signal ... exiting\n"; exit; };
$SIG{ALRM} = sub { print "Timed out\n"; exit; };
alarm 5;
for ( 1 .. 100 ) {
system("echo $_ > /tmp/myfifo");
}
alarm 0;
exit;
-----------------
Some things to consider that are not included in the scripts above -
* autoflush may need to be turned on. With syslogd, I don't think it
matters that much, since, from my understanding, it doesn't buffer it's
output. But, it is something to consider.
* it works only on a *NIX type platform (Linux, SunOS, FreeBSD (maybe -
FreeBSD has tighter security, so it may not work as expected)).
* you may need to alter your signal handlers to suit your needs.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL.
http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Wiker's Law: Government expands to absorb revenue and then some.