bmcpanel

Well-Known Member
Jun 1, 2002
544
0
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:
 

MrHits

Well-Known Member
Oct 31, 2001
92
0
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
 

bmcpanel

Well-Known Member
Jun 1, 2002
544
0
316
Originally posted by MrHits
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
Thanks MrHits. WIll try this test run now.
 

bmcpanel

Well-Known Member
Jun 1, 2002
544
0
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 "/".
 
Last edited:

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
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.
 

bmcpanel

Well-Known Member
Jun 1, 2002
544
0
316
Originally posted by dgbaker
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.
Thanks DG. I will try this momentarily in a test directory and let you know the results.
 

PWSowner

Well-Known Member
Nov 10, 2001
2,901
4
343
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
 

bmcpanel

Well-Known Member
Jun 1, 2002
544
0
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!
 

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
Toronto, Ontario Canada
cPanel Access Level
DataCenter Provider
Originally posted by squirrel
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

Good catch Mike, yep it should not be -R for the last one.
 

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
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.