Solved

problem with PERL script to lock file - flock()

Posted on 2008-10-04
7
695 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
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 84

Expert Comment

by:ozo
ID: 22641161
Perhaps /tmp//var/www/cgi-bin/ is not the correct directory to use on the other server
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

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

Accepted Solution

by:
ozo earned 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

867 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

25 Experts available now in Live!

Get 1:1 Help Now