[opensuse] script to modify file permissions
Hi openSUSE 12.1 umask 0022 In a shared folder, we want any file created to be group rw. Using acls is not an option. #!/bin/sh share=/home/CACTUS/dropbox/ cd $share wihile true do if [ -N $share ]; then for a in * do if [ -N $a ]; then echo $(chmod g+w $a) echo "$a was changed" fi done fi sleep 4 done But it's changing _all_ the files in the folder irrespectively: hh3:/home/CACTUS/dropbox # touch lynn lynn was changed hh3:/home/CACTUS/dropbox # touch lynn2 lynn was changed lynn2 was changed hh3:/home/CACTUS/dropbox # touch lynn3 lynn was changed lynn2 was changed lynn3 was changed I thought it may be changing the timestamp: hh3:/home/CACTUS/dropbox # touch lynn4 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn2 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn3 -rw-rw---- 1 root 3000016 0 Feb 20 12:30 lynn4 but no. Each time only one file has been modified. Why does it change _all_ of the files? Thanks, L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 20-02-12 12:39, lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
#!/bin/sh share=/home/CACTUS/dropbox/ cd $share wihile true do if [ -N $share ]; then for a in * do if [ -N $a ]; then echo $(chmod g+w $a) echo "$a was changed" fi done fi sleep 4 done
But it's changing _all_ the files in the folder irrespectively: hh3:/home/CACTUS/dropbox # touch lynn lynn was changed
hh3:/home/CACTUS/dropbox # touch lynn2 lynn was changed lynn2 was changed
hh3:/home/CACTUS/dropbox # touch lynn3 lynn was changed lynn2 was changed lynn3 was changed
I thought it may be changing the timestamp: hh3:/home/CACTUS/dropbox # touch lynn4 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn2 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn3 -rw-rw---- 1 root 3000016 0 Feb 20 12:30 lynn4 but no.
Each time only one file has been modified. Why does it change _all_ of the files? Thanks, L x
The script says for a in * (all files in the directory) instead of for a in $* (all files in the argument list) Furthermore I'm not sure if it's wise to call this script "touch" instead of "mytouch" Regards, -- Jos van Kan registered Linux user #152704 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2012-02-20 21:18, Jos van Kan wrote:
The script says for a in * (all files in the directory) instead of for a in $* (all files in the argument list)
Furthermore I'm not sure if it's wise to call this script "touch" instead of "mytouch"
I also thought the same, but that's not what is happening. The script runs in a permanent loop, scanning all files matching some test, and then changing the attributes. There is no argument to the script. Touch is external, to test the script action. - -- Cheers / Saludos, Carlos E. R. (from 11.4 x86_64 "Celadon" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAk9Cr88ACgkQIvFNjefEBxrHLwCgtmjm+EFoA/RZfXYgWOaFh/cI TNcAni7BfsyxPsimQLD8gL/iNR/VjHIl =bA0G -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 20-02-12 21:40, Carlos E. R. wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 2012-02-20 21:18, Jos van Kan wrote:
The script says for a in * (all files in the directory) instead of for a in $* (all files in the argument list)
Furthermore I'm not sure if it's wise to call this script "touch" instead of "mytouch" I also thought the same, but that's not what is happening. The script runs in a permanent loop, scanning all files matching some test, and then changing the attributes. There is no argument to the script.
Touch is external, to test the script action.
- -- Cheers / Saludos,
Carlos E. R. (from 11.4 x86_64 "Celadon" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/
iEYEARECAAYFAk9Cr88ACgkQIvFNjefEBxrHLwCgtmjm+EFoA/RZfXYgWOaFh/cI TNcAni7BfsyxPsimQLD8gL/iNR/VjHIl =bA0G -----END PGP SIGNATURE----- Oops. You're right. (Same player shoots again)
[ -N file ] is true if the file has been modified since it was last read, according to man bash. None of the lynn* files are being read, so the condition remains true for all those files. Regards, -- Jos van Kan registered Linux user #152704 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2012-02-20 22:10, Jos van Kan wrote:
[ -N file ] is true if the file has been modified since it was last read, according to man bash.
Ah, I didn't know that one. I suppose it check one of the timestamps :-?
None of the lynn* files are being read, so the condition remains true for all those files.
Ah, I see. Or I don't :-), but it makes sense. In this case tracking famd would be useful, somehow, to see if the directory changes (ie, new or modified, file). I have never seen that in scripts, no idea how to do it in fact. - -- Cheers / Saludos, Carlos E. R. (from 11.4 x86_64 "Celadon" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAk9CyRQACgkQIvFNjefEBxrTtwCdFclYIR5S3xzKkv7Hpy5nC04M 7WMAn2GbcLdVi4NTvBKYO+j/35SzWyOv =aUU3 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Tue, 21 Feb 2012 08:58:36 Carlos E. R. wrote:
On 2012-02-20 22:10, Jos van Kan wrote:
[ -N file ] is true if the file has been modified since it was last read, according to man bash.
Ah, I didn't know that one. I suppose it check one of the timestamps :-?
atime - the time the file was last accessed (unless the filesystem is mounted with the noatime option in which case the atime attribute is never updated). -- =================================================== Rodney Baker VK5ZTV rodney.baker@iinet.net.au =================================================== -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 02/20/2012 09:18 PM, Jos van Kan wrote:
On 20-02-12 12:39, lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
#!/bin/sh share=/home/CACTUS/dropbox/ cd $share wihile true do if [ -N $share ]; then for a in * do if [ -N $a ]; then echo $(chmod g+w $a) echo "$a was changed" fi done fi sleep 4 done
But it's changing _all_ the files in the folder irrespectively: hh3:/home/CACTUS/dropbox # touch lynn lynn was changed
hh3:/home/CACTUS/dropbox # touch lynn2 lynn was changed lynn2 was changed
hh3:/home/CACTUS/dropbox # touch lynn3 lynn was changed lynn2 was changed lynn3 was changed
I thought it may be changing the timestamp: hh3:/home/CACTUS/dropbox # touch lynn4 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn2 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn3 -rw-rw---- 1 root 3000016 0 Feb 20 12:30 lynn4 but no.
Each time only one file has been modified. Why does it change _all_ of the files? Thanks, L x
The script says for a in * (all files in the directory) instead of for a in $* (all files in the argument list)
Furthermore I'm not sure if it's wise to call this script "touch" instead of "mytouch"
Regards,
Hi No, I think it's OK. The script is called rw. I used the Unix touch command as a quick way to make a file when I was testing rw. Thanks for the explanation. I nearly understand it. BTW, what's the difference between /bin/sh and bin/bash? L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Monday 20 February 2012, lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
#!/bin/sh share=/home/CACTUS/dropbox/ cd $share wihile true do if [ -N $share ]; then for a in * do if [ -N $a ]; then echo $(chmod g+w $a) echo "$a was changed" fi done fi sleep 4 done
But it's changing _all_ the files in the folder irrespectively: hh3:/home/CACTUS/dropbox # touch lynn lynn was changed
hh3:/home/CACTUS/dropbox # touch lynn2 lynn was changed lynn2 was changed
hh3:/home/CACTUS/dropbox # touch lynn3 lynn was changed lynn2 was changed lynn3 was changed
I thought it may be changing the timestamp: hh3:/home/CACTUS/dropbox # touch lynn4 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn2 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn3 -rw-rw---- 1 root 3000016 0 Feb 20 12:30 lynn4 but no.
Each time only one file has been modified. Why does it change _all_ of the files?
Just change only files without the wanted permissions find "$share" ! -perm -g=w -print0 | xargs -0 chmod g+w This also corrects any quoting issues in case there are strange file names.
Thanks, L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Tuesday 21 February 2012, Ruediger Meier wrote:
On Monday 20 February 2012, lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
#!/bin/sh share=/home/CACTUS/dropbox/ cd $share wihile true do if [ -N $share ]; then for a in * do if [ -N $a ]; then echo $(chmod g+w $a) echo "$a was changed" fi done fi sleep 4 done
But it's changing _all_ the files in the folder irrespectively: hh3:/home/CACTUS/dropbox # touch lynn lynn was changed
hh3:/home/CACTUS/dropbox # touch lynn2 lynn was changed lynn2 was changed
hh3:/home/CACTUS/dropbox # touch lynn3 lynn was changed lynn2 was changed lynn3 was changed
I thought it may be changing the timestamp: hh3:/home/CACTUS/dropbox # touch lynn4 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn2 -rw-rw---- 1 root 3000016 0 Feb 20 12:26 lynn3 -rw-rw---- 1 root 3000016 0 Feb 20 12:30 lynn4 but no.
Each time only one file has been modified. Why does it change _all_ of the files?
Just change only files without the wanted permissions find "$share" ! -perm -g=w -print0 | xargs -0 chmod g+w
better find "$share" ! -perm -g=w -print0 | xargs -r -0 chmod g+w to avoid error if no file is found.
This also corrects any quoting issues in case there are strange file names.
Thanks, L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 21/02/12 01:37, Ruediger Meier wrote:
On Tuesday 21 February 2012, Ruediger Meier wrote:
On Monday 20 February 2012, lynn wrote:
share=/home/CACTUS/dropbox/ cd $share wihile true do if [ -N $share ]; then for a in * do if [ -N $a ]; then echo $(chmod g+w $a) echo "$a was changed" fi done fi sleep 4 done
B
Each time only one file has been modified. Why does it change _all_ of the files? Just change only files without the wanted permissions find "$share" ! -perm -g=w -print0 | xargs -0 chmod g+w better find "$share" ! -perm -g=w -print0 | xargs -r -0 chmod g+w to avoid error if no file is found.
This also corrects any quoting issues in case there are strange file names.
Very neat. Should I test before doing the find? #!/bin/sh share=/home/CACTUS/dropbox/ while true do if [ -N $share ]; then find "$share" ! -perm -g=w -print0 | xargs -r -0 chmod g+w fi sleep 4 done As the other files will already be rw, is there a way to 'only do the find if a new file has been created'? Thanks, L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Tuesday 21 February 2012, lynn wrote:
On 21/02/12 01:37, Ruediger Meier wrote:
On Tuesday 21 February 2012, Ruediger Meier wrote:
On Monday 20 February 2012, lynn wrote:
share=/home/CACTUS/dropbox/ cd $share wihile true do if [ -N $share ]; then for a in * do if [ -N $a ]; then echo $(chmod g+w $a) echo "$a was changed" fi done fi sleep 4 done
B
Each time only one file has been modified. Why does it change _all_ of the files?
Just change only files without the wanted permissions find "$share" ! -perm -g=w -print0 | xargs -0 chmod g+w
better find "$share" ! -perm -g=w -print0 | xargs -r -0 chmod g+w to avoid error if no file is found.
This also corrects any quoting issues in case there are strange file names.
Very neat. Should I test before doing the find?
It's not needed because find "" .... does not find anything and nothing will be chmoded.
#!/bin/sh share=/home/CACTUS/dropbox/ while true do if [ -N $share ]; then find "$share" ! -perm -g=w -print0 | xargs -r -0 chmod g+w fi sleep 4 done
As the other files will already be rw, is there a way to 'only do the find if a new file has been created'?
You could try the inotify-tools package, something like while inotifywait -r -e "$share" ;do ... ;done (I've never used it in practice so far.) The best way would be IMO to mount "$share" with the right umask somehow like Michael mentioned in the other post. So you wouldn't need your script at all. cu, Rudi
Thanks, L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
I've read that it's possible to set a umask option for a bind mount, so would remounting the folder be an option? I haven't tried it myself - but it might be worth a shot. On Tue, 21 Feb 2012 00:39:42 lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
... -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 02/21/2012 11:53 AM, michael@actrix.gen.nz wrote:
I've read that it's possible to set a umask option for a bind mount, so would remounting the folder be an option? I haven't tried it myself - but it might be worth a shot.
On Tue, 21 Feb 2012 00:39:42 lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
... Mmm. I can only change the umask globally. Can it be done on a per folder basis? L x
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Sorry - I've done some googling and testing. Although bind mount accepts a umask it doesn't apply it. To explain the concept here is an example of what I tried - the following does not work... # mount --bind -o umask=0 /tmp /mnt/tmp2/ # touch /mnt/tmp2/xyz # ls -l /mnt/tmp2/xyz -rw-r--r-- 1 root root 0 Feb 22 07:39 /mnt/tmp2/xyz Some file system types allow a umask to be specified, but not the standard ones (see man mount). So I don't think that will fly. I wouldn't consider using inotifywait - its formatting options for filenames with spaces in them is difficult for shell scripts to process. And even worse, it claims to have bugs that can lead it to miss changes. It's a bit disappointing - only a toy. It would be a cool project to create something better. So I think you are stuck with a looping shell script. If you're really keen it would be possible to write a umask virtual filesystem using Linux fuse - but I guess you don't want to do any C programming. If you do I can supply some pointers (I've written collectfs - a fuse folder protecting file system, it collects any file clobbered or deleted by any process). Interesting problem. On Wed, 22 Feb 2012 04:46:59 lynn wrote:
On 02/21/2012 11:53 AM, michael@actrix.gen.nz wrote:
I've read that it's possible to set a umask option for a bind mount, so would remounting the folder be an option? I haven't tried it myself - but it might be worth a shot.
On Tue, 21 Feb 2012 00:39:42 lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
... Mmm. I can only change the umask globally. Can it be done on a per folder basis? L x
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Tuesday 21 February 2012, michael@actrix.gen.nz wrote:
Sorry - I've done some googling and testing. Although bind mount accepts a umask it doesn't apply it. To explain the concept here is an example of what I tried - the following does not work...
# mount --bind -o umask=0 /tmp /mnt/tmp2/ # touch /mnt/tmp2/xyz # ls -l /mnt/tmp2/xyz -rw-r--r-- 1 root root 0 Feb 22 07:39 /mnt/tmp2/xyz
Some file system types allow a umask to be specified, but not the standard ones (see man mount). So I don't think that will fly.
This is BTW very pity because it makes standard file systems unusable for external HDs or USB sticks to be shared between systems with different users. IMO we need something like gid, uid or umask as mount option for ext. I always wondered how external media could be used without using fat/ntfs. However I don't use external media at all so never investigated it.
I wouldn't consider using inotifywait - its formatting options for filenames with spaces in them is difficult for shell scripts to process. And even worse, it claims to have bugs that can lead it to miss changes. It's a bit disappointing - only a toy. It would be a cool project to create something better.
So I think you are stuck with a looping shell script.
If you're really keen it would be possible to write a umask virtual filesystem using Linux fuse - but I guess you don't want to do any C programming. If you do I can supply some pointers (I've written collectfs - a fuse folder protecting file system, it collects any file clobbered or deleted by any process).
Interesting problem.
On Wed, 22 Feb 2012 04:46:59 lynn wrote:
On 02/21/2012 11:53 AM, michael@actrix.gen.nz wrote:
I've read that it's possible to set a umask option for a bind mount, so would remounting the folder be an option? I haven't tried it myself - but it might be worth a shot.
On Tue, 21 Feb 2012 00:39:42 lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
...
Mmm. I can only change the umask globally. Can it be done on a per folder basis? L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 02/21/2012 09:15 PM, michael@actrix.gen.nz wrote:
Sorry - I've done some googling and testing. Although bind mount accepts a umask it doesn't apply it. To explain the concept here is an example of what I tried - the following does not work...
# mount --bind -o umask=0 /tmp /mnt/tmp2/ # touch /mnt/tmp2/xyz # ls -l /mnt/tmp2/xyz -rw-r--r-- 1 root root 0 Feb 22 07:39 /mnt/tmp2/xyz
Some file system types allow a umask to be specified, but not the standard ones (see man mount). So I don't think that will fly.
I wouldn't consider using inotifywait - its formatting options for filenames with spaces in them is difficult for shell scripts to process. And even worse, it claims to have bugs that can lead it to miss changes. It's a bit disappointing - only a toy. It would be a cool project to create something better.
So I think you are stuck with a looping shell script.
If you're really keen it would be possible to write a umask virtual filesystem using Linux fuse - but I guess you don't want to do any C programming. If you do I can supply some pointers (I've written collectfs - a fuse folder protecting file system, it collects any file clobbered or deleted by any process).
Interesting problem.
On Wed, 22 Feb 2012 04:46:59 lynn wrote:
On 02/21/2012 11:53 AM, michael@actrix.gen.nz wrote:
I've read that it's possible to set a umask option for a bind mount, so would remounting the folder be an option? I haven't tried it myself - but it might be worth a shot.
On Tue, 21 Feb 2012 00:39:42 lynn wrote:
Hi openSUSE 12.1 umask 0022
In a shared folder, we want any file created to be group rw. Using acls is not an option.
... Mmm. I can only change the umask globally. Can it be done on a per folder basis? L x
Hi There is an alternative using POSIX acl's to control the the creation of files:
setfacl -d -m g::rw /home/CACTUS/dropbox lynn2@hh3:/home/CACTUS> touch dropbox/h lynn2@hh3:/home/CACTUS> ls -la dropbox/ total 8 drwxrws---+ 2 root suseusers 4096 Feb 19 11:13 . drwxr-xr-x 9 root root 4096 Feb 19 11:11 .. -rw-rw---- 1 lynn2 suseusers 0 Feb 19 11:13 h The reason I need the script is because I'm exporting the directory over NFS and even though the acls are translated to nfs4 acl's correctly: mount -t nfs4 hh3:/home /mnt nfs4_getfacl /mnt/CACTUS/dropbox/ A::OWNER@:rwaDxtTcCy A::GROUP@:rwaDxtcy A::EVERYONE@:tcy A:fdi:OWNER@:rwaDxtTcCy A:fdi:GROUP@:rwaDtcy A:fdi:EVERYONE@:tcy the files on the mounted share are not created with rw permissions. lynn2@hh3:/mnt/CACTUS/dropbox> touch h3 gives: -rw-r----- 1 lynn2 suseusers 0 Feb 19 11:19 h2 I think this is a bug with the POSIX <--> nfs4 mapping. I have a thread open on nfs acls here, on the nfs-kernel list and on the Samba list but no luck as yet. It seems that no one has been here before. So yes, you are right. I am stuck with a workaround script:-( Thanks for your time, L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (6)
-
Carlos E. R.
-
Jos van Kan
-
lynn
-
michael@actrix.gen.nz
-
Rodney Baker
-
Ruediger Meier