Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Help. I did something dumb.

Discussion in 'General Discussion' started by bmcpanel, Jun 11, 2004.

  1. bmcpanel

    bmcpanel Well-Known Member

    Joined:
    Jun 1, 2002
    Messages:
    546
    Likes Received:
    0
    Trophy Points:
    316
    I was changing ownership on a customers .htaccess file

    Ran

    chown -R user.user .*

    Guess what it did. It followed the ./ up one directory and proceeded to change theownership of all customers to "user.user".

    Is there a script somewhere that will change ownership back to the correct settings, or must I manually change 300 customers back by hand?

    Thanks. :confused:
     
  2. MrHits

    MrHits Well-Known Member

    Joined:
    Oct 31, 2001
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    306
    cd /home/

    test run, will show what it will do:
    ls -al|awk {'print "chown -R " $3"."$3 " " $3'}

    add the |sh at the end to actually execute it:
    ls -al|awk {'print "chown -R " $3"."$3 " " $3'}|sh
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. bmcpanel

    bmcpanel Well-Known Member

    Joined:
    Jun 1, 2002
    Messages:
    546
    Likes Received:
    0
    Trophy Points:
    316
    Thanks MrHits. WIll try this test run now.
     
  4. bmcpanel

    bmcpanel Well-Known Member

    Joined:
    Jun 1, 2002
    Messages:
    546
    Likes Received:
    0
    Trophy Points:
    316
    Ran:
    ls -al|awk {'print "chown -R " $3"."$3 " " $3'}


    And it didn't really fix the problem. The problem is, my directory looks like this.....

    drwx--x--x 10 derf derf 4096 Jun 11 00:10 uncleroy/
    drwx--x--x 8 derf derf 4096 Jun 11 12:15 uvlighth/
    drwx--x--x 15 derf derf 4096 Jun 11 00:10 vacation/
    drwx--x--x 8 derf derf 4096 Jun 11 00:10 vanam/
    drwx--x--x 8 derf derf 4096 Jun 11 00:10 vertical/
    drwx--x--x 17 derf derf 4096 Jun 11 11:45 vns100/
    drwx--x--x 13 derf derf 4096 Jun 11 15:34 vns100b/

    What the command does is to run a chown command with the existing user.group.

    ====================
    chown -R derf.derf derf
    chown -R derf.derf derf
    chown -R derf.derf derf
    chown -R derf.derf derf
    chown -R derf.derf derf
    chown -R derf.derf derf
    chown -R derf.derf derf
    ======================

    The result is the same as before....

    ======================
    drwx--x--x 10 derf derf 4096 Jun 11 00:10 uncleroy/
    drwx--x--x 8 derf derf 4096 Jun 11 12:15 uvlighth/
    drwx--x--x 15 derf derf 4096 Jun 11 00:10 vacation/
    drwx--x--x 8 derf derf 4096 Jun 11 00:10 vanam/
    drwx--x--x 8 derf derf 4096 Jun 11 00:10 vertical/
    drwx--x--x 17 derf derf 4096 Jun 11 11:45 vns100/
    drwx--x--x 13 derf derf 4096 Jun 11 15:34 vns100b/
    =========================================


    I tried this at shell also, but got an error..

    for i in `ls`;do chown -R $i:$i $i ; done

    ======= RESULTS ====================
    chown: `uncleroy/:uncleroy/': invalid user
    chown: `uvlighth/:uvlighth/': invalid user
    chown: `vacation/:vacation/': invalid user
    chown: `vanam/:vanam/': invalid user
    chown: `vertical/:vertical/': invalid user
    chown: `vns100/:vns100/': invalid user
    chown: `vns100b/:vns100b/': invalid user
    ==================================

    I guess the error is that the script reads i$ from the user directory itself, example: "vacation/" includes the "/" which makes the error because the "/" is not part of the actual user and does not match the username.

    vacation/ Wrong
    vacation Right

    Wish I knew how to make the variable i$ ignore the "/".
     
    #4 bmcpanel, Jun 11, 2004
    Last edited: Jun 11, 2004
  5. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,574
    Likes Received:
    3
    Trophy Points:
    343
    Location:
    Toronto, Ontario Canada
    cPanel Access Level:
    DataCenter Provider
    Try this...

    cd /home

    for i in `ls -bA /var/cpanel/users`;do chown -R $i:$i $i;done
    for i in `ls -bA /var/cpanel/users`;do chown -R $i:mail $i/mail;done
    for i in `ls -bA /var/cpanel/users`;do chown -R $i:mail $i/etc;done
    for i in `ls -bA /var/cpanel/users`;do chown -R $i:nobody $i/public_html;done

    That should do it.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    4
    Trophy Points:
    343
    Location:
    ON, Canada
    Now there's why I've asked dg for help with shell functions. I could write a perl script to fix the ownerships, but I would not have been able to give you the code he did. ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. bmcpanel

    bmcpanel Well-Known Member

    Joined:
    Jun 1, 2002
    Messages:
    546
    Likes Received:
    0
    Trophy Points:
    316
    Thanks DG. I will try this momentarily in a test directory and let you know the results.
     
  8. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    4
    Trophy Points:
    343
    Location:
    ON, Canada
    Should work. I don't know shell coding enough to write something like that off the top of my head, but I do know enough to know what that does. I just need to study lots of dg's little scripts to learn enough to write them. ;)

    What it does is get the list of usernames from /var/cpanel/users and with each username it does the chowning by substituting the $i's for the usernames. The first line is saying "for each username in /var/cpanel/users, chown username:username username recursively" which is why you want to be in the home directory first. The next 3 lines just do the same modified to repair the ownerships that aren't supposed to be username:username.

    I think the last line needs to be changed though. Remove the -R. I think we only want the public_html directory to be username:nobody, not everything below it.
    for i in `ls -bA /var/cpanel/users`;do chown $i:nobody $i/public_html;done
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. bmcpanel

    bmcpanel Well-Known Member

    Joined:
    Jun 1, 2002
    Messages:
    546
    Likes Received:
    0
    Trophy Points:
    316
    dgbaker, thank you, thank you, thank you. You just saved me a ton of time and aggravation! If you're ever in Savannah, Georgia, the beer's on me!
     
  10. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,574
    Likes Received:
    3
    Trophy Points:
    343
    Location:
    Toronto, Ontario Canada
    cPanel Access Level:
    DataCenter Provider

    Good catch Mike, yep it should not be -R for the last one.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,574
    Likes Received:
    3
    Trophy Points:
    343
    Location:
    Toronto, Ontario Canada
    cPanel Access Level:
    DataCenter Provider
    Glad to help, anytime. :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. bmcpanel

    bmcpanel Well-Known Member

    Joined:
    Jun 1, 2002
    Messages:
    546
    Likes Received:
    0
    Trophy Points:
    316
    Ah. Didn't catch the last line. I have made the correction. Thanks again.
     
  13. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    4
    Trophy Points:
    343
    Location:
    ON, Canada
    As long as I keep studying your samples I'll eventually be writing my own. ;)

    The difference between this shell scripting and perl seems to be mostly the formatting.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,574
    Likes Received:
    3
    Trophy Points:
    343
    Location:
    Toronto, Ontario Canada
    cPanel Access Level:
    DataCenter Provider
    That's basically the difference between most, it's always the formatting. I do a lot of TCL during the day and most of the times it is formatting that gets messed up if something is wrong.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    4
    Trophy Points:
    343
    Location:
    ON, Canada
    You just keep writing scripts when people ask and I'll keep studying. :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice