Need help writing a simple script to chown files
john
lists.john at gmail.com
Thu Aug 2 19:26:15 BST 2007
Thanks Jim,
By the way are your students using unix or are they using Windows and
dropping stuff to a SAMBA share? If SAMBA why did you chose the method
of preserving file ownership your mentioned rather than using some
switch in smb.conf like "force create mode ="?
I am just wondering since I have been toying with the idea of a
"dropbox" as well.
Thanks for your help!
John
On 8/2/07, Jim Kronebusch <jim at winonacotter.org> wrote:
> > Luckily each directory name is the same as the user who should own the file.
> > So what I want to do is have a script that goes recursively through and
> > chown's -R the directory called STUDENT_A to be owned STUDENT_A etc.
> >
> > So that it looks like:
> >
> > drwx------ 8 student_a domain users 4096 2007-08-01 15:26 STUDENT_A
> > drwx------ 10 ANO_STU_B domain users 4096 2007-08-01 15:26 ANO_STU_B
> >
> > I am sure this should be really easy but my attempts to do this have
> > failed.
> >
> > Anyway, any thoughts would be appreciated!
> >
> > Thanks!
>
> I have been running this script for the last 3 years or so now every minute to do close
> to what you want:
>
> #!/bin/bash
> for file in /home/Drop/*
> do owner=$(ls -ld \
> "$file"\
> |awk '{print $3}')
> chown -R $owner \
> "$file"
> done
>
> I have a folder called Drop in /home/Drop and inside these folders is a folder for every
> teacher (/home/Drop/Teachername). I have set the correct permissions on the teachers
> folder but students drop homework into their respective teacher's folders and the newly
> written file is owned by the student, when I need it owned by the teacher. So the
> script chowns all files recursively with the owner that is set for the
> /home/Drop/teachername. This isn't exactly what you are looking for but might easily be
> modified to what you need. I haven't tested but I think if you change the "ls -ld" on
> line 3 to "ls -l" and change the "print $3" to "print $9" I think it will do what you
> want. See below:
>
> #!/bin/bash
> for file in /home/Drop/*
> do owner=$(ls -l \
> "$file"\
> |awk '{print $9}')
> chown -R $owner \
> "$file"
> done
>
> --
> This message has been scanned for viruses and
> dangerous content by the Cotter Technology
> Department, and is believed to be clean.
>
>
> --
> edubuntu-users mailing list
> edubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/edubuntu-users
>
More information about the edubuntu-users
mailing list