Short background: I need to control permissions for a unix file (directory) using ZABBIX to see if they have changed / when they change. For this, ZABBIX does not have any built-in functions, such as vfs.file.mode [xxxx], so I had to collapse my own UserParameter with a numeric type.
What I'm doing so far is to use ls -l | cut -c 2-10to get the parts rwxr-xr-x, and then use sedto convert the letters to their "weight" and awkusing substrto summarize, to get a numeric 755or any other value.
Currently, on Solaris, I don't have the GNU coreutils team stat, and I want it to be portable and efficient, and only using standard unix tools that are always available. (IMHO, perl is not always available).
My first attempt (example for the root directory):
ls -ld / | \
cut -c 2-10 | \
sed -e 's%-%0%g' -e 's%r%4%g' -e 's%w%2%g' -e 's%x%1%g' | \
awk '{print (100 * ((substr($0,1,1)) + (substr($0,2,1)) + (substr($0,3,1))) + \
(10 * ((substr($0,4,1) + (substr($0,5,1)) + (substr($0,6,1)) ))) + \
( (substr($0,7,1)) + (substr($0,8,1)) + (substr($0,9,1)) ) );}'
As you can see, I don't need the setuid bits or anything other than files, but purist answers are always welcome!
Of course, there should be a more elegant solution. Perhaps a standard unix tool that I did not think about.
I found this place "by chance" about a week ago, and I really like it! It is amazing to see that a lot of knowledge, skills and friendliness in one place! This is my first question, so I am very happy if I get an answer! :-) Thank you very much!