Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problem with PERL script to lock file - flock()

Posted on 2008-10-04
7
Medium Priority
?
740 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
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 

Author Comment

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

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

Industry Leaders: 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

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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
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 …

722 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