Solved

problem with PERL script to lock file - flock()

Posted on 2008-10-04
7
681 Views
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";
5   flock LOCK,LOCK_EX|LOCK_NB;

When the script runs I get the following error -

test_lock.pl: flock() on closed filehandle LOCK at /var/www/cgi-bin/test_lock.pl line 5.

when I print $lockfile I get the following -

/tmp//var/www/cgi-bin/test_lock.pl.lock

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

Richard
0
Comment
Question by:rwinnick
  • 4
  • 3
7 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
#What do you get with
open LOCK,">>$lockfile" or die "$lockfile $!";
0
 

Author Comment

by:rwinnick
Comment Utility
browser shows -

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

error_log shows -

test_lock.pl: /tmp//var/www/cgi-bin/test_lock.pl.lock No such file or directory at /var/www/cgi-bin/test_lock.pl line 4.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Perhaps /tmp//var/www/cgi-bin/ is not the correct directory to use on the other server
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rwinnick
Comment Utility
how would I check this ??
0
 
LVL 84

Accepted Solution

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

Author Comment

by:rwinnick
Comment Utility
sorry to be slow but just a beginner at this
where would i put the above -
thanks
0
 

Author Comment

by:rwinnick
Comment Utility
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 -
R
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now