I have one file, and I need everything that is written in some time frame to that file to be written to a second file.
What is the best way to do so? Open some thread that will read the file and do so ?
Any ideas ?
I have one file, and I need everything that is written in some time frame to that file to be written to a second file.
What is the best way to do so? Open some thread that will read the file and do so ?
Any ideas ?
The tee
utility might be what you're looking for:
#! /usr/bin/perl
use warnings;
use strict;
my @files = qw/ file1 file2 /;
open my $fh, "| tee @files >/dev/null"
or die "$0: start tee failed: $!";
print $fh "$_\n" for map int rand 10, 1 .. 5;
close $fh or warn "$0: close tee: $!";
Sample run:
$ ./write-both $ cat file1 0 7 5 8 2 $ cat file2 0 7 5 8 2