- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Fixing user files
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
Discussions
Discussions
Forums
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
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
тАО07-13-2009 11:19 AM
тАО07-13-2009 11:19 AM
Fixing user files
I am trying to fix files which do not have users. I am using the following find command for it.
find / \( -nouser -o -nogroup \) | xargs ls -ld
Suppose it gives us an output of
-rwxr----- 1 12345 user_unix 943 Jan 13 12:12 /home/abcd/.profile
From the above output it is obvious that this file belongs to user "abcd" but is owned by 12345 which does not exist in /etc/passwd.
Can someone help me with a command or maybe a couple of lines of script to change the file to be owned by user "abcd" from "12345". I have many files like this that needs to be changed.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 11:24 AM
тАО07-13-2009 11:24 AM
Re: Fixing user files
find / \( -nouser -o -nogroup \) | xargs chown abcd
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 11:25 AM
тАО07-13-2009 11:25 AM
Re: Fixing user files
would do it. If you have many of them you could redirect the output of your "nouser/nogroup/ command to a file and then use that as input to a for loop.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 11:30 AM
тАО07-13-2009 11:30 AM
Re: Fixing user files
find / \( -nouser -o -nogroup \) | xargs ls -ld > /tmp/ownerless_files
then process this file in a way like this:
cat /tmp/ownerless_files | while read line
do
owner=`echo $line | awk {'print $3'}`
group=`echo $line | awk {'print $4'}`
filename=`echo $line | awk {'print $9'}`
if [ "${owner}" = "12345" ]
then
chown abcd ${filename}
fi
#replicate the above 'if' block as many times as necessary depending on
#conditions you want to test for users and groups
done
This should do it.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 11:35 AM
тАО07-13-2009 11:35 AM
Re: Fixing user files
# find /path \( -nouser -o -nogroup \) -exec chown abcd {} +
Be careful. I would limit your '/path' to that which is known to require change. You don't want to capricioulsy transfer ownership of files.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 11:53 AM
тАО07-13-2009 11:53 AM
Re: Fixing user files
#!/usr/bin/sh
find / \( -nouser -o -nogroup \) | xargs ls -ld > /tmp/test
cat /tmp/test | while read line
do
owner=`echo $line | awk {'print $3'}`
group=`echo $line | awk {'print $4'}`
filename=`echo $line | awk {'print $9'}`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 12:00 PM
тАО07-13-2009 12:00 PM
Re: Fixing user files
If you want all the files under "/home/abcd/"
to be owned by user "abcd", then you might
write a script which loops through all the
directories "/home/*", and does a "find -exec"
on each one. If you want only the owner-less
or group-less files to be affected, then
that's also possible.
While working on your script, you might wish
to add an "echo" command to your "-exec"
clause, so that you can see what will happen
_before_ you wreck something.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 12:06 PM
тАО07-13-2009 12:06 PM
Re: Fixing user files
> I am getting a syntax error "do" is not matched.
Well, try adding a closing 'done'. You are making this harder than it needs to be.
# find /path \( -nouser -o -nogroup \)|xargs -t -n1 chown abcd
...gives you a trace and the change.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 12:06 PM
тАО07-13-2009 12:06 PM
Re: Fixing user files
Right, I only want to change those found to be unowned by the find command. Can you please spell out the loop here on how do i change it.
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2009 12:21 PM
тАО07-13-2009 12:21 PM
Re: Fixing user files
cat /tmp/test | while read line
do
owner=`echo $line | awk {'print $3'}`
group=`echo $line | awk {'print $4'}`
filename=`echo $line | awk {'print $9'}`
# do something here
done
this above is your construct.
you can replace
# do something here
line with either:
(1)
*********************************
if [ "${owner}" = "12345" ]
then
chown abcd ${filename}
fi
*********************************
or
(2)
*********************************
chown abcd ${filename}
*********************************
Option number (2) is the same as what any of the find blah-blah | xargs chown blah-blah will give you as the result.
Your problem definition is very vague. If you state what you want done from the get-go, this thread would not stretch this long. Sysadmins are pretty much like computers. They do what you "tell" them to do not what "want" done. WIsh I have mind reading capabilities but it is coming in my Mel Burslan V2.0 in the next life.
UNIX because I majored in cryptology...