Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

problem with PERL script to lock file - flock()

Posted on 2008-10-04
7
Medium Priority
?
746 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 85

Expert Comment

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

Author Comment

by:rwinnick
ID: 22641146
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 85

Expert Comment

by:ozo
ID: 22641161
Perhaps /tmp//var/www/cgi-bin/ is not the correct directory to use on the other server
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rwinnick
ID: 22641180
how would I check this ??
0
 
LVL 85

Accepted Solution

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

Author Comment

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

Author Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

971 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