LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-06-2006, 06:28 PM   #1
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Rep: Reputation: 30
change ownership script


hi there,

i'm trying to write a script that changes the ownership of the file .procmailrc in all the users home directories as their's

for instance at the moment it's like this

[root@mail pma]# ls -lsa
total 28
4 drwx------ 3 pma 10000 4096 Apr 7 09:27 .
12 drwxrwxrwx 490 root root 12288 Apr 7 08:10 ..
4 drwx------ 3 pma 10000 4096 Apr 7 09:20 mail
8 -rwx------ 1 root root 4441 Apr 7 09:27 .procmailrc

i want it to look like this for everyone

[root@mail pma]# ls -lsa
total 28
4 drwx------ 3 pma 10000 4096 Apr 7 09:27 .
12 drwxrwxrwx 490 root root 12288 Apr 7 08:10 ..
4 drwx------ 3 pma 10000 4096 Apr 7 09:20 mail
8 -rwx------ 1 pma 10000 4441 Apr 7 09:27 .procmailrc
 
Old 04-06-2006, 07:02 PM   #2
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Code:
$ su
# cut -f1,6 -d: /etc/passwd | sed -e's/:/ /' -e's/^/chown /' -e's/$/\/.procmailrc/' > /tmp/doit.sh
# vi /tmp/doit.sh   (verify that this looks like what you want to do, then...)
# sh -x /tmp/doit.sh
#
 
Old 04-06-2006, 07:23 PM   #3
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Original Poster
Rep: Reputation: 30
thats a great script! i'm impressed by it, but i'm using winbind with virtual users ... so there not listed in the /etc/passwd file ...
 
Old 04-07-2006, 07:59 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
This one is not as smart as heartig's, but what about:

Code:
cd /home
for nfile in *
do
        if [ -d $nfile ] && [ -e /home/$nfile/.procmailrc ]
        then
           chown $nfile:10000 /home/$nfile/.procmailrc
        fi
done
Obviously you have to run it as root.

This changes the .procmail rc to the user as owner. If you want to change to owner 'pma' change the
chown $nfile ...
to
chown pma ...
This was not quite clear to me.

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot change ownership jamaso Slackware 11 11-08-2010 11:01 AM
Change ownership apffal SUSE / openSUSE 1 11-09-2005 02:08 AM
How to change ownership of a drive? raid517 Linux - Software 1 09-15-2005 08:15 AM
unable to change ownership arjunjeyaprakash Linux - Newbie 12 09-06-2005 02:02 PM
change ownership Johng Linux - General 4 04-06-2004 02:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration