unable to write output of a fifo file to a log file
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
unable to write output of a fifo file to a log file
I am trying to read from a fifo file and append that along with the date to a log file.
I am able to write only the first line to the log "Starting the log".
But the write within the while loop after reading from the fifo doesnt happen.
It does only if I open the log file for writing within the while loop.
I want to be able to open the log for appending and write to it anywhere from the proceeding loops. Can someone please help fix the code.
#!/usr/bin/perl
use Path::Class;
#use autodie;
my $fifo = "pcode.pipe";
my $fifoh;
my $fifolog = "/nfs/home/kummit01/lab/fifo.log";
open($fifoh, "+< $fifo") or die "The FIFO file cant be found";
open (LOGH, "+>>$fifolog") or die "The Log file cant be opened";
print LOGH "Startintg the log\n";
while (<$fifoh>) {
chomp ($_);
$pattern = '^[A-Z]{1,2}[0-9]{1,2}?\s[0-9][A-Z][A-Z]$';
if ($_ =~ /$pattern/) {
#open (LOGH, ">>$fifolog") or die "The Log file cant be opened";
print "Match Success \n";
$timeNow = localtime(time);
print LOGH ("$_ $timeNow");
} else {
print "No Match \n";
}
}
close $fifoh;
close $logh;
exit (0);
#!/usr/bin/perl -w
my $fifo = "pcode.pipe";
my $fifolog = "/nfs/home/kummit01/lab/fifo.log";
$fifolog = "fifo.log";
open(F, "<$fifo") or die "The FIFO file cant be found";
open (LOGH, ">$fifolog") or die "The Log file cant be opened $!";
printf(LOGH "Starting the log\n");
$|=1;
while (<F>) {
chomp($_);
if (/^[A-Z]{1,2}[0-9]{1,2}?\s+[0-9][A-Z][A-Z]$/) {
print "Match Success\n";
$timeNow = localtime(time);
printf(LOGH "%s - %s\n", $_, $timeNow); $|=1;
} else {
print "No Match\n";
}
}
exit (0);
If you've got stuck remove the pipe and make a new one.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.