best way to distribute an item to everyones homedir?
James
oscartheduck at gmail.com
Sun Oct 28 10:12:16 PDT 2007
On 10/28/07, Jonathan Horne <freebsd at dfwlp.com> wrote:
>
> On Sunday 28 October 2007 09:21:55 you wrote:
> > maildir=/path/to/your/custom/maildir
> >
> > for dir in `ls /usr/home`
> > do
> > cp -r $maildir /usr/home/$dir/
> > done
>
> thanks james. quick question... will that put the proper owner and chmod
> of
> the target homedirs, on the new directories?
>
> thanks,
> --
> Jonathan Horne
> http://dfwlpiki.dfwlp.org
> freebsd at dfwlp.com
>
...what an interesting question. Let me check.
Okay, a couple of things. First, for the copy command, make sure that you
don't include a trailing slash for the source directory, otherwise it copies
the contents of the directory and not the directory itself. So:
pclmills# cp -r COPYME ~james/
NOT:
pclmills# cp -r COPYME/ ~james/
This will set the group permission correctly, not the user, and the
permissions are in accordance with umask. So the result of the above copy
is:
[james at pclmills ~]$ ls -l | grep COPYME
drwxr-xr-x 2 root james 512 Oct 28 11:03 COPYME
And the file inside the directory gets:
[james at pclmills ~]$ cd COPYME/
[james at pclmills ~/COPYME]$ ls -l
total 0
-rw-r--r-- 1 root james 0 Oct 28 11:03 file
As you've got configuration scripts, if your umask is the same as mine then
this should be fine.
It's reasonably trivial, of course, to add a line to the copy script to use
chmod and chown to change the permissions as you want them to be changed.
the $dir variable in the above for loop contains the name of the home
directory. If this is the same name as the UID/GID (which it is by default)
then even though it looks weird something like:
chown -R $dir:$dir /usr/home/$dir/$maildir
will get you close. Of course, remember this warning from man chown:
-R Change the user ID and/or the group ID of the specified
directory
trees (recursively, including their contents) and files.
Beware
of unintentionally matching the ``..'' hard link to the parent
directory when using wildcards like ``.*''.
How I do something like this is to build the script one line at a time using
test directories that I set up. Do that first and everything should be
tickety boo.
I put the mailing list's address back in the cc line of this email; use
"reply all", not reply, to hit the whole mailing list and have people who
are *far* better scripters than me chime in with helpful hints ;)
James
More information about the freebsd-questions
mailing list