Solved

problem with PERL script to lock file - flock()

Posted on 2008-10-04
7
723 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

738 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