Unix Technical Forum

etc/skel - change owner when adduser?

This is a discussion on etc/skel - change owner when adduser? within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Hi I have a bunch of default files in my skel directory, problem is, when i adduser the files ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-19-2008, 08:36 AM
Morten Lundstrøm
 
Posts: n/a
Default etc/skel - change owner when adduser?

Hi

I have a bunch of default files in my skel directory, problem is, when i
adduser the files are just copied keeping the user that created them in the
skel dir owner, i need the newly added user to be owner of the files copied
to his home dir, I've been trying to add a chown command to the adduser
script, but I've never done scripts before so I have no idea where to start
or what I'm doing wrong.
Any help/ideas?
I tried googling for it but came up empty (I have a nasty habbit of always
using the wrong words :-()

Thanks
Morten

--
Replace .hej with .com in my e-mail prior to sending e-mail.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-19-2008, 08:36 AM
Alan Hicks
 
Posts: n/a
Default Re: etc/skel - change owner when adduser?

In alt.os.linux.slackware, Morten Lundstrøm dared to utter,
> I've been trying to add a chown command to the adduser
> script, but I've never done scripts before so I have no idea where to start
> or what I'm doing wrong.
> Any help/ideas?


Here's what I would do. (Many lines snipped.) This is on a Slackware
9.0 machine. Your version may be slightly different.

# Add the account to the system
CMD="$useradd "$HME" -m "$EXP" "$U_ID" "$GID" "$AGID" "$SHL" "$LOGIN""
$CMD

if [ $? -gt 0 ]; then
echo "- Error running useradd command -- account not created!"
echo "(cmd: $CMD)"
exit 1
fi

# These next few lines are what you need to add.
# Copy the contents of /etc/skel to the user's home directory.
cp -aR /etc/skel/* "${HME}"

# Change the owner and group of those files.
chown -R "${U_ID}":"${GID}" "${HME}"

# Set the finger information
$chfn "$LOGIN"
if [ $? -gt 0 ]; then
echo "- Warning: an error occurred while setting finger information"
fi

--
It is better to hear the rebuke of the wise,
Than for a man to hear the song of fools.
Ecclesiastes 7:5
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-19-2008, 08:37 AM
Claudiu Cismaru
 
Posts: n/a
Default Re: etc/skel - change owner when adduser?

> I have a bunch of default files in my skel directory, problem is, when
> i adduser the files are just copied keeping the user that created them
> in the skel dir owner, i need the newly added user to be owner of the
> files copied to his home dir, I've been trying to add a chown command
> to the adduser script, but I've never done scripts before so I have no
> idea where to start or what I'm doing wrong.
> Any help/ideas?


The useradd command does this for you. This is the DEFAULT behavoir.

moya:/etc/skel# ls
moya:/etc/skel# touch mumu
moya:/etc/skel# ls -l mumu
-rw-r--r-- 1 root root 0 Feb 21 10:36 mumu
moya:/etc/skel# useradd -m test
moya:/etc/skel# ls -l /home/test/mumu
-rw-r--r-- 1 test users 0 Feb 21 10:36 /home/test/mumu

Just be sure to use -m or to use adduser script in order the homedir to
be created and files copied!

--
Claudiu Cismaru

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-19-2008, 08:37 AM
Morten Lundstrøm
 
Posts: n/a
Default Re: etc/skel - change owner when adduser?


"Claudiu Cismaru" <claudiu@cnixs.com> skrev i en meddelelse
news:c175h8$1f298e$1@ID-225382.news.uni-berlin.de...
> > I have a bunch of default files in my skel directory, problem is, when
> > i adduser the files are just copied keeping the user that created them
> > in the skel dir owner, i need the newly added user to be owner of the
> > files copied to his home dir, I've been trying to add a chown command
> > to the adduser script, but I've never done scripts before so I have no
> > idea where to start or what I'm doing wrong.
> > Any help/ideas?

>
> The useradd command does this for you. This is the DEFAULT behavoir.
>
> moya:/etc/skel# ls
> moya:/etc/skel# touch mumu
> moya:/etc/skel# ls -l mumu
> -rw-r--r-- 1 root root 0 Feb 21 10:36 mumu
> moya:/etc/skel# useradd -m test
> moya:/etc/skel# ls -l /home/test/mumu
> -rw-r--r-- 1 test users 0 Feb 21 10:36 /home/test/mumu


Hehe, I must have been sleepy when I did it, I only had 3 users on my system
when I changed my skel dir, so I decided just to manually copy the files,
next day when I checked the ownership was incorrect... *oops*
Sorry for taking your time with a stupid question like that one :-)

/Morten


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-19-2008, 08:37 AM
Morten Lundstrøm
 
Posts: n/a
Default Re: etc/skel - change owner when adduser?


"Alan Hicks" <1001298936@carrier.lizella.net> skrev i en meddelelse
news:slrnc3d81b.au3.1001298936@carrier.lizella.net ...
> In alt.os.linux.slackware, Morten Lundstrøm dared to utter,
> > I've been trying to add a chown command to the adduser
> > script, but I've never done scripts before so I have no idea where to

start
> > or what I'm doing wrong.
> > Any help/ideas?

>
> Here's what I would do. (Many lines snipped.) This is on a Slackware
> 9.0 machine. Your version may be slightly different.
>
> # Add the account to the system
> CMD="$useradd "$HME" -m "$EXP" "$U_ID" "$GID" "$AGID" "$SHL" "$LOGIN""
> $CMD
>
> if [ $? -gt 0 ]; then
> echo "- Error running useradd command -- account not created!"
> echo "(cmd: $CMD)"
> exit 1
> fi
>
> # These next few lines are what you need to add.
> # Copy the contents of /etc/skel to the user's home directory.
> cp -aR /etc/skel/* "${HME}"
>
> # Change the owner and group of those files.
> chown -R "${U_ID}":"${GID}" "${HME}"
>
> # Set the finger information
> $chfn "$LOGIN"
> if [ $? -gt 0 ]; then
> echo "- Warning: an error occurred while setting finger information"
> fi


Thanks, I just figured my mistake out myself, Sorry for taking your time :-)

/Morten

--
Replace .hej with .com in my e-mail prior to sending e-mail.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:17 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com