#!/usr/local/bin/perl -w ###################################################################### # excat -- 2004, Mike Schilli ###################################################################### # cat, but synchronizing access via file.lock ###################################################################### use strict; my $VERSION = "0.01"; my $CVSVERSION = '$Revision: 1.2 $'; use Fcntl qw/:flock/; use Getopt::Std; my $lockfile = ".lock"; getopts("l:", \my %opts); $lockfile = $opts{l} if exists $opts{l}; open(WFILE, ">>$lockfile") || die "Error opening $lockfile ($!)"; flock(WFILE, LOCK_EX); # start of critical region while(<>) { print; } close(WFILE); unlink $lockfile; # might fail __END__ =head1 NAME excat - cat command with file locking =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS cat source | excat -l file.lock >>dest =head1 OPTIONS =over 8 =item B<-l> Specify the name of the lock file. Defaults to '.lock'. =back =head1 DESCRIPTION C acts like C, but creates a lockfile and ensures exclusive access before opening the output stream. =head1 EXAMPLES $ excat -l file.lock sourcefile >>destfile $ cat sourcefile | excat -l file.lock >>destfile =head1 LEGALESE Copyright 2004 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR 2004, Mike Schilli