We have various of machines here with all sorts of hardware and Operating Systems, most of them do regular tasks with bash that an agent executes. However it came to my attention that some Solaris machines we own do not have stat util, and adding it would be a problem that might take time (ironic)
Meanwhile I was trying to imitate one sisyphean task which stat did in a magnificent way: return the file permissions in Octal
I found some old example which prints the regular permissions in Octal - rwx, but not for the "special" permissions - sticky group, sticky user, etc
My basic method was this : first calculate the special bits Octal value and then add the regular 'rwx', but it doesn't seem to work well
ls -lah $file | awk '{k=0;for(i=0;i<=8;i++) {if (substr($1,i+2,1)~/[s]/) k += ((substr($1,i+2,1)~/[s]/)*2^9);else k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));}if (k)printf("%0o ",k);}'
ls -lah $file | awk '{k=0;for(i=0;i<=8;i++){k+=((substr($1,i+2,1)~/[rwxs]/)*2^(8-i));printf("%0o\n",k)}if(k)printf("%0o ",k);}'
can anyone hint me what would be a good solution ?