1835087 Members
2202 Online
110073 Solutions
New Discussion

Need help with a script

 
SOLVED
Go to solution
S-un-B-ix-S
Advisor

Need help with a script

One of our junior admins accidentally did a recursive chown in our main home directory and now alot of our user directory have incorrect ownership. I have a list of the users that have the incorrect info. I need to parse out the name and the group ID from the passwd file and then apply it to all of the directories themselves and the files within those directories.

can anyone help me with this? thanks so much.
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Need help with a script

Hi:

Hmmm. OK, you can do this:

# cat .fixme
#!/usr/bin/sh
while read NAME
do
GROUP=$(awk -F: -v NAME=${NAME} '$1==NAME {print $4}' /etc/passwd)
echo chown -R ${NAME} ${GROUP} /home/${NAME}
done < usernames

...where 'usernames' has the account names to "fix", one per line.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: Need help with a script

Shalom,

Actually you need to compare the system with an undamaged one and make the change.

ls -R > good.sys.txt
ls -R > bad.sys.txt

You may need to do this directory by directory.

You can't just remap things from /etc/passwd.

If it were Linux, you could do an rpm -qf for every rpm and use that to check and change the ownership.

This is a process that involves manual work. Its also a good way for a junior admin to pay for his/her mistake and learn the importance of permissions.

After that a test plan.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Need help with a script

HI (AGAIN):

Well, is appears that my second comment in your duplicate post in the Language family was deleted by a moderator because you posted your query twice.

Thus:

If by "main home directory" you do NOT mean '/home' but rather something disasterous like '/', then:

# swverify -F \*

...will repair the permissions and ownership of products and patches represented by entries in the IPD (Installed Product Database --- '/var/adm/sw').

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Need help with a script

Hi:

ALSO, please re-examine your earlier thread here:

https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1144475

...to see if the answers therein answered that query. Thanks!

...JRF...
S-un-B-ix-S
Advisor

Re: Need help with a script

Scripts were most useful, thanks.