Hi,
I'm writing a simple script which gets input from a fifo (which is fed by 
syslog as well) and prints out the names and accounts uf "User unknow in 
recipient table".
Here is the code:

===================
#!/usr/bin/perl
use strict;
use warnings;

# DUMP user table
open (USERS, "config/passwd") or die ("Unable to open PASSWD: $!\n");
my %users;
while(<USERS>)        {
        my($username,$uid,$gid) = (split(/:/,$_))[0,2,3];
        #print "$gid\n";
        next unless ($gid eq 100);
        $users{$username}="";
}
close USERS;


# PARSE maillog from FIFO
open (FIFO, "</tmp/fifo-mennox") or die ("Unable to open FIFO for reading! $!");
open (OUTPUT, ">>unknown_users_list.txt") or die ("Unable to open OUTPUT for 
writing! $!");

while(<FIFO>)   {
        next unless ($_ =~ /User unknown/);
        my ($address) = $_ =~ /^.*to=<([^> ]+)>/;
        my ($username) = (split(/\x40/,$address))[0];
        next if $username =~ /^$/;
        #printf OUTPUT ("%-50s\t%-20s\n",$address,$username) if 
(exists($users{$username}));
        printf OUTPUT ("%-50s\t%-20s\n",$address,$username);
}
close OUTPUT;

========================


The problem is that if I "tail -f" the output file for screening the results 
while they are written, my script ends up writing at all.
No problem if I never open the file until I stop the execution of my script.
It seems I have a problem with a concurrent access to the same file, one in 
"append" mode (my script), the other in read-only mode (tail -f).
Maybe tail (or 'cat' as well, it's the same) affects the file inode so that it 
stops perl from writing?
Any help would be appreciated
TIA

Mariano




-- 
-----------------------------
Mariano Cunietti
System Administrator
Enter S.r.l.
Via  Stefanardo da Vimercate, 28
20128 - Milano - Italy
Tel.  +39 02 25514319
Fax   +39 02 25514303
[EMAIL PROTECTED]
www.enter.it - www.enterpoint.it
-----------------------------
Gruppo Y2K - www.gruppoy2k.it


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to