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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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…

830 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