Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to chdir to where the fiefox profiel ID is

    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:

    Code:
    #!/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:

    Code:
    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.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by goude View Post
    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:

    Code:
    #!/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:

    Code:
    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

  • #3
    New Coder
    Join Date
    Jul 2009
    Posts
    91
    Thanks
    5
    Thanked 6 Times in 6 Posts
    I won't ask why :-)

    Code:
    #!/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 :-)
    Last edited by clunk.werclick; 10-10-2009 at 02:06 PM.

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    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

    Code:
    #!/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";
    }

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by clunk.werclick View Post
    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

  • #6
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Quote Originally Posted by oesxyl View Post
    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.

    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?

  • #7
    New Coder
    Join Date
    Jul 2009
    Posts
    91
    Thanks
    5
    Thanked 6 Times in 6 Posts
    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 :-)

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by FishMonger View Post
    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.

    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?
    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

  • #9
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Quote Originally Posted by clunk.werclick View Post
    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.

  • #10
    New Coder
    Join Date
    Jul 2009
    Posts
    91
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by FishMonger View Post
    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*
    Last edited by clunk.werclick; 10-10-2009 at 07:43 PM.

  • #11
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    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.
    Last edited by vinyl-junkie; 10-12-2009 at 12:37 PM. Reason: signatures only allowed through the control panel

  • #12
    New Coder
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi


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

    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
    Code:
    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.

  • #13
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by goude View Post
    Hi


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

    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
    Code:
    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

  • #14
    New Coder
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #15
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by goude View Post
    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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •