Am 15. Nov, 2012 schwätzte Edward Ned Harvey (lopser) so:
moin moin,
I'm running a script as root, I'm going to parse a file. I can easily test
that the file is owned by root. I want to test if the group or other write bit
is set.
If using "find" you can test that a file is writable by yourself - but not test
if it's writable by anyone else.
If using "stat" you can get the perms in drwxrwxrws format. But the number of characters sometimes varies,
based on whether or not it's a character special device, directory, softlink, etc. Also, the leading or trailing blank
character ' ' space may or may not be present for different implementations of stat. So although it's definitely
possible to find the "w" bit in the "g" and "o" fields... I am hesitant to do this.
Also, even if I want to do this, it's not immediately obvious to me, how to extract the nth character out of a string
in a bash script.
Not sure about the various implmentations of stat issue, but the string
parsing part is doable with string operators.
( perms=$( stat -c %A /tmp/file ); echo "${perms}:${perms:5:1}:${perms:8:1}" )
-rw-rw-rw-:w:w
${parameter:offset:length}
I believe the first 10 characters of the access rights should always be
file type followed by the three groups of three. I believe all the things
like se linux that add stuff add it after the first 10 characters.
ciao,
der.hans
--
# http://www.LuftHans.com/ http://www.LuftHans.com/Classes/
# But getting smart is a tricky business. The smartest people I've ever met
# are the ones who knew exactly what they were ignorant of. -- Alan Alda
# Southamton commencement speech, 2007May18_______________________________________________
Tech mailing list
[email protected]
https://lists.lopsa.org/cgi-bin/mailman/listinfo/tech
This list provided by the League of Professional System Administrators
http://lopsa.org/