Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determinig numeric permissions 2

Status
Not open for further replies.

stawolg

Technical User
Sep 25, 2001
28
DE
How can I automatically (!) deternine the numerical permission value of a file? With a single command (I dont know any, didnt find it anywhere) or with a small script.

command "file" -> output "755" or so....
 
you will have to define the term "small" in reference to a script. it should take at least ten lines but i have not thought much about the problem.

i suggest using several cut commands to put the various parts (rwx or what have you) into some variables then do a simple string check. if you want to get fancy you can use perl, but ksh works fine. either that or get used to interpreting them visually, i don't know of a prog that does this for you.

IBM Certified -- AIX 4.3 Obfuscation
 
Yes certainly I started to do some perl ;-)..
but I was looking in parallel for one of those famous undocumented commands, you wont find in the manuals...
 
Hi,

This one came out bigger then 10 lines ...:
================================
#!/bin/ksh
#Usage : check <filename>
#Displays the numeric permission value for files and directories

set –A INC 4 2 1 4 2 1 4 2 1
integer I=0 #counter for the array
integer count=0 #counter for the owner/group/other position
integer sum=0 #sums the digit
for BYTE in 2 3 4 5 6 7 8 9 10 ;do
if [[ `ls –ld $1|awk '{ print $1 }'|cut –c $BYTE` != &quot;-&quot; ]] ;then
sum=$sum+${INC}
fi
I=$I+1
count=$count+1
if (( $count == 3 )) ;then
echo “$sum\c”
sum=0
count=0
fi
done
echo “”
================================

&quot;Long live king Moshiach !&quot;
 
Hi,

write a little file called convert.bc containing the two lines:
obase=8
ibase=2

and
ls -l /path/to/your_file|awk '{print $1}'|tr 'rwx-' '1110'|bc -l convert.bc
 
found on the news:

perl -e 'printf(&quot;%o\n&quot;, (stat(&quot;'&quot;$filename&quot;'&quot;))[2] & 07777)'
 
Yes, thanks a lot! Meanwhile I wrote my Perl script and it works even with the t and s-bits, but I didnt know the stat or any octal commands so I build a rather lengthy workaround for it...The last idea by ogniemi is extremely nice, now I found the same idea in the Camel book of Perl.
Thx to you all!
(PS: our task was to rebuild all permissions in the /etc fs
and along all links in it on a 4.3.3 machine. User made a su - root, tried to make a &quot;chmod -R 644 $path/etc/*&quot; but his variable $path was empty! As /etc/ is linked to /usr/sbin nearly every system command wasnt executable anymore...)
 
star for ogniemi, just used that line today.

IBM Certified -- AIX 4.3 Obfuscation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top