- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Help with script to chown of home directory
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2005 06:09 AM
12-11-2005 06:09 AM
I would like to change this, any ideas on a script that would work. I attempted to just do an ls -d -l -t | awk '{print $9}'; cut -c 7-15
However, I can't figure out the best way to get this setup and work with the chown $1 $1.
I am not to sure how to approach this, any ideas?
Solved! Go to Solution.
- Tags:
- chown
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2005 06:28 AM
12-11-2005 06:28 AM
Re: Help with script to chown of home directory
This should do what you want:
#!/usr/bin/sh
for D in `ls -ld /home/*|awk '{print $NF}'`
do
chown -R ${D} ${D##*/}:users
done
exit 0
Regards!
...JRF...
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2005 06:35 AM
12-11-2005 06:35 AM
Solutionawk -F: '$3 > 100 {printf("%s %d %s\n", $1, $4, $6)}' /etc/passwd | while read user gid home
do
chown ${user}:${gid} ${home}
done
You could also do a chown -R; however, that'd be a little riskier. I'd suggest echoing the command in the loop above out (echo chown...) to see which home directories and users are getting changed before looking at the -R option.
The $3 > 100 *should* prevent you from changing the ownership of any system related files/directories.
HTH;
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2005 06:36 AM
12-11-2005 06:36 AM
Re: Help with script to chown of home directory
for D in `ls -ld /home/*|awk '{print $NF}'`
do
chown -R ${D} ${D##*/}:users
done
exit 0
----- very close thanks
#!/usr/bin/sh
for D in `ls -ld /home/*|awk '{print $NF}'`
do
chown -R ${D##*/}:users ${D}
done
exit 0
--- this worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2005 06:37 AM
12-11-2005 06:37 AM
Re: Help with script to chown of home directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2005 06:39 AM
12-11-2005 06:39 AM