...

View Full Version : how to chdir to where the fiefox profiel ID is



goude
10-09-2009, 03:55 PM
Hi everyone

I'm trying to write a small perl script that will cd into the hidden .mozilla directory and delete the .parentlock file.

Here is the script:


#!/usr/bin/perl
use strict;
use warnings;

my $user=`$ENV{USER}`;
chomp($user);

my $dir="/home/$user/.mozilla/firefox/xxxxxxxx.default/";

chdir $dir or die "Can't change directory to $dir:$!\n" if $dir;
my $del=`rm -f .parentlock`;

Ofourse I get the error:


Can't change directory to /home/pam/.mozilla/firefox/xxxxxxxx.default/:No such file or directory

I don't really know how to define the 8 random numbers/letters that are included in the directory name where the .parentlock file is located.

This directory normally looks like this z1pc46q7.default and the first 8 "characters" are different for each user.

Is there a way to chdir to that particular directory without defining the exact directory name (i.e. z1pc46q7.default)?

Hope that makes sense. Any suggestions please?

Thanks a lot.

oesxyl
10-09-2009, 06:28 PM
Hi everyone

I'm trying to write a small perl script that will cd into the hidden .mozilla directory and delete the .parentlock file.

Here is the script:


#!/usr/bin/perl
use strict;
use warnings;

my $user=`$ENV{USER}`;
chomp($user);

my $dir="/home/$user/.mozilla/firefox/xxxxxxxx.default/";

chdir $dir or die "Can't change directory to $dir:$!\n" if $dir;
my $del=`rm -f .parentlock`;

Ofourse I get the error:


Can't change directory to /home/pam/.mozilla/firefox/xxxxxxxx.default/:No such file or directory

I don't really know how to define the 8 random numbers/letters that are included in the directory name where the .parentlock file is located.

This directory normally looks like this z1pc46q7.default and the first 8 "characters" are different for each user.

Is there a way to chdir to that particular directory without defining the exact directory name (i.e. z1pc46q7.default)?

Hope that makes sense. Any suggestions please?

Thanks a lot.
can you explain why do you want to do this?

best regards

clunk.werclick
10-10-2009, 02:03 PM
I won't ask why :-)


#!/usr/bin/perl -w
use strict;
my $user=`whoami`;
chomp($user);
my $dir= `find /home/$user/.mozilla/firefox/ -name *.default`;
chomp($dir);
my $filetorm = $dir."/.parentlock";
print $filetorm. "\n";
#`rm -f $filetorm`;

It's not the most graceful or terse way to do it, but it should do what you wish. The line that does the damage is commented out and a print replaces it above.

This will bail out with: No such file or directory
if the user running the script does not have the path. I'll leave you to trap for that :-)

FishMonger
10-10-2009, 03:12 PM
4 things:

1) There is no need to shell out via the backticks to get the user.
See: perldoc perldata and search for ENV

2) Use the glob function to locate the file.
See: perldoc -f glob

3) There is no need to cd to the directory before deleting the file.

4) There is no need to shell out to the rm command.
See: perldoc -f unlink


#!/usr/bin/perl

use strict;
use warnings;

my $lockfile = glob("/home/$ENV{USER}/.mozilla/firefox/*.default/.parentlock");
my $deleted = unlink $lockfile;

if ( $deleted ) {
print "Successfully deleted: '$lockfile'\n";
}
else {
print "Failed to delete: '$lockfile' <$!>\n";
}

oesxyl
10-10-2009, 03:21 PM
I won't ask why :-)
you should ask, because I'm pretty sure that op try to solve a configuration problem and what he/she ask is not the best way to do that. :-)
that .parentlock have a purpose there.

best regards

FishMonger
10-10-2009, 03:55 PM
you should ask, because I'm pretty sure that op try to solve a configuration problem and what he/she ask is not the best way to do that. :-)
that .parentlock have a purpose there.

best regards

I agree with you and that's part of the reason why I didn't post a solution yesterday when I first saw this question.

However, if people want to take the wrong approach in "fixing" the problem, then as long as it doesn't compromise the system or another user, then maybe we should let them go down the wrong path and hopefully learn not to do it the next time. :rolleyes:

OTOH, the more they go down the wrong path, the more likely they'll be asking for fixes to their convoluted patches. Am I being cynical? :rolleyes:

clunk.werclick
10-10-2009, 04:48 PM
1 thing:


It's not the most graceful or terse way to do it, but it should do what you wish..


I don't do the Politics - opinions are so tiresome when you've had +30 years of boys arguing semantics :-)

oesxyl
10-10-2009, 05:22 PM
I agree with you and that's part of the reason why I didn't post a solution yesterday when I first saw this question.

However, if people want to take the wrong approach in "fixing" the problem, then as long as it doesn't compromise the system or another user, then maybe we should let them go down the wrong path and hopefully learn not to do it the next time. :rolleyes:

OTOH, the more they go down the wrong path, the more likely they'll be asking for fixes to their convoluted patches. Am I being cynical? :rolleyes:
I have a apocalyptical view of how this will end, I talk about programming in general, :)
To have a idea of a small part of what I imagine take a look over the php forum, :)
I can't imagine how so many people can write forms and make big sites without knowing that somewhere is something called http protocol.
I'm afraid I'm more cynical then you, :)

best regards

FishMonger
10-10-2009, 06:33 PM
1 thing:


I don't do the Politics - opinions are so tiresome when you've had +30 years of boys arguing semantics :-)

I too try to stay out of politics (I can't afford bribing the politicians), but don't you think that we should post quality and efficient code, especially if we have 30+ years experience and it takes little or no extra effort?. :)

FYI, my original post was directed to the OP, not you.

clunk.werclick
10-10-2009, 07:25 PM
I too try to stay out of politics (I can't afford bribing the politicians), but don't you think that we should post quality and efficient code, especially if we have 30+ years experience and it takes little or no extra effort?. :)


1. Is there any difference in the quality of the code - or is that just your opinion too? Like your implied view that what I have posted is *not* quality or efficient. It may be different to how you elect to do it, but there is no difference in quality or efficiency as far as I can tell. Again, this is just opinion and like assholes - everyone has one.
2. You were given the opportunity to post 'quality efficient code' but elected to post crap in a condescending tone. That does *not* make you *better* than other people, it makes you an arsehole IMHO.

Like I say, I don't do politics, if you want a fight go and beat your boyfriend. Make up your mind, it's either an issue with asking the OP why, or an issue with the code or you just wanting to abuse the OP and show just how superior you are. *yawn*

sathugvi
10-12-2009, 10:13 AM
you should ask, because I'm pretty sure that op try to solve a configuration problem and what he/she ask is not the best way to do that. :-)
that .parentlock have a purpose there.

best regards

Glad to hear you're using this: I plan to keep it much more aggressively up-to-date than has been the case in the past, but don't hesitate to let me know if you find errors or need clarifications.

goude
10-12-2009, 02:18 PM
Hi


First of all thank you all for your replies/help in solving my problem.:thumbsup:

The reason I want to delete the .parentlock file is because when firefox crashes you get that famous error saying firefox is already running please restart your computer. Sometimes firefox is indeed still running and in that case I simply kill it


killall -9 firefox-bin

however most of the time is this file that causes the problem.

I'm sure there is a reason that .parentlock exists in that directory but upon deletion firefox recreates it so no harm there.

oesxyl
10-12-2009, 02:32 PM
Hi


First of all thank you all for your replies/help in solving my problem.:thumbsup:

The reason I want to delete the .parentlock file is because when firefox crashes you get that famous error saying firefox is already running please restart your computer. Sometimes firefox is indeed still running and in that case I simply kill it


killall -9 firefox-bin

however most of the time is this file that causes the problem.

I'm sure there is a reason that .parentlock exists in that directory but upon deletion firefox recreates it so no harm there.
you are on windows? this "restart your computer" never happend to me. If you are on linux what distro you use, and what windows manager?
Anyway it must be a configuration problem. For me if is happend to kill the browse when I restart it again will ask if I want to start a new session or to restore the old one and I never need to take care of parentlock.
If you use gnome and pidgin for example, after you delete the parentlock when you click in pidgin on a link, pidgin will ask gnome to check if there is a browser open and if not will ask to open one. Because parentlock is gone gnome will decide that you have no browser and will try to open one.
This is an example, but many application are bind togheter this way, so you imagine what mess you can do doing this way, :)

best regards

goude
10-12-2009, 02:53 PM
No, I'm using Fedora 11 (Leonidas) with KDE.
I understand what you are saying oesxyl but in fedora this error occurs every now and then. I don't know about other distro.

The exact error is:
Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system.

So sometimes I kill it but usually have to delete .parentlock to make it work again.

Thank you all again.

Best wishes and greetings from Greece

oesxyl
10-12-2009, 03:09 PM
No, I'm using Fedora 11 (Leonidas) with KDE.
I understand what you are saying oesxyl but in fedora this error occurs every now and then. I don't know about other distro.

The exact error is:
Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system.

So sometimes I kill it but usually have to delete .parentlock to make it work again.

Thank you all again.

Best wishes and greetings from Greece
when you use kde or gnome you feel same pain as you run windows, :)
Many years ago I was using redhat but when they lounch fedora I moved to debian.
Usualy yum and rpm will not let's you to mix incompatible library but sometimes will do. Check if firefox dependences, probably there is a problem.

best regards

FishMonger
10-12-2009, 05:10 PM
goude,

I'm glade we were able to help and I apologize for the distraction that several of our posts may have caused.

Since the subject of efficiency was brought up by me, I think I should show benchmark examples that demonstrate the issue.


#!/usr/bin/perl

use strict;
use warnings;
use Benchmark qw(:all);

print "\ncomparing perl %ENV hash lookup vs backticks to whoami\n";
cmpthese(-10, {
'%ENV' => sub { my $user = $ENV{USER} },
'whoami' => sub { my $user = `whoami`; },
});


print "\n\ncomparing perl glob vs backticks to find\n";
cmpthese(-10, {
'glob' => sub { my $lockfile = glob("/root/.mozilla/firefox/*.default/.parentlock"); },
'find' => sub { my $dir = `find /root/.mozilla/firefox/ -name *.default`;
chomp($dir);
my $filetorm = $dir."/.parentlock";},
});


print "\n\ncomparing perl unlink vs backticks to rm\n";
cmpthese(-10, {
'unlink' => sub { unlink '/root/.mozilla/firefox/pnev8p16.default/.parentlock' },
'rm' => sub { `rm -f /root/.mozilla/firefox/pnev8p16.default/.parentlock` },
});


The results of the benchmark tests are sorted from least efficient to most efficient.


[root@fc4dev ~]# ./benchmark.pl

comparing perl %ENV hash lookup vs backticks to whoami
Rate whoami %ENV
whoami 1266/s -- -100%
%ENV 1061300/s 83743% --


comparing perl glob vs backticks to find
Rate find glob
find 1316/s -- -92%
glob 17247/s 1211% --


comparing perl unlink vs backticks to rm
Rate rm unlink
rm 1490/s -- -99%
unlink 142508/s 9462% --



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum