problem with PERL script to lock file - flock()

Posted on 2008-10-04
Last Modified: 2013-12-25
Hi -
Have PERL script that has the following code to lock the file when executing as follows -

1   #!/usr/bin/perl -w
2   use Fcntl ':flock'; # import LOCK_* constants
3   my $lockfile = join("","/tmp/","$0",".lock");
4   open LOCK,">>$lockfile";

When the script runs I get the following error - flock() on closed filehandle LOCK at /var/www/cgi-bin/ line 5.

when I print $lockfile I get the following -


This code ran fine on a previous server -
Any insights really appreciated -
I am stumpped -

Question by:rwinnick
  • 4
  • 3
LVL 84

Expert Comment

ID: 22641093
#What do you get with
open LOCK,">>$lockfile" or die "$lockfile $!";

Author Comment

ID: 22641146
browser shows -

/tmp//var/www/cgi-bin/ No such file or directory at /var/www/cgi-bin/ line 4.

error_log shows - /tmp//var/www/cgi-bin/ No such file or directory at /var/www/cgi-bin/ line 4.
LVL 84

Expert Comment

ID: 22641161
Perhaps /tmp//var/www/cgi-bin/ is not the correct directory to use on the other server
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.


Author Comment

ID: 22641180
how would I check this ??
LVL 84

Accepted Solution

ozo earned 500 total points
ID: 22641204
#maybe you can
use File::Path;
mkpath( '/tmp//var/www/cgi-bin', {verbose => 1} );

Author Comment

ID: 22641213
sorry to be slow but just a beginner at this
where would i put the above -

Author Comment

ID: 22641307
hi ozo -
figured out where to put it :-)
seems to work ok now -
how can I 'fix' things on the server so that I don't have to use the make path thing in all my code -
we can make this another question if you think appropriate -
thanks -

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question