#!/usr/local/bin/perl ########################## ## Just an illustration of file locking. ## This time, with a DBM file. ## This illustration is a simplified version from ## the DB_File man page. If you don't understand ## the perl here, just skip it for now. ## use Fcntl; # defines constants used by flock use DB_File; my $file = '/homes/home8/adabyron/cgi-bin/dboutput'; $ENV{PATH} = ''; $ENV{ENV} = ''; $netid = $ENV{REMOTE_USER} ? $ENV{REMOTE_USER} : 'nobody'; print "Content-type: text/plain\n\n"; my $fh = tie ( %h, 'DB_File', $file, O_CREAT|O_RDWR, 0600 ); unless ($fh) { print "Can't open $file\n"; exit; } ## get file descriptor my $fd = $fh->fd; ## open a file handle corresponding to file descriptor open (DB, "+<&=$fd"); ## Now lock file handle for writing flock(DB, LOCK_EX); ## Write file by assigning to hash $h{$netid} = `/usr/bin/date`; ## Sync buffer $fh->sync; ## Unlock file flock(DB, LOCK_UN); ## Clean up. undef $fh; untie %h; close DB; print "File has been written\n";