help please!!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help please!!!!
# 1  
Old 04-15-2008
help please!!!!

how do you get the file permissions to strings
like rwx------ read,write,executable to users
# 2  
Old 04-15-2008
Rather than going for a script, see if the command aclget solves your purpose.

Code:
man aclget

# 3  
Old 04-15-2008
check if this is what you want:
Code:
stat -c '%A' filename

or
Code:
stat -c '%a' filename

# 4  
Old 04-15-2008
Quote:
Originally Posted by Yogesh Sawant
check if this is what you want:
Code:
stat -c '%A' filename

or
Code:
stat -c '%a' filename

Can the result from this be used as a variable..I mean if a file has following permissions
rwxr-xr--
I want the output to be:
this file has the following permissions:-
Read, Write and Execute for the user.
Read and Execute for the group.
Read only for the others.


Is it possible?
# 5  
Old 04-16-2008
maybe something like :-

filename=$1
uperms=`ls -l $filename|cut -c2-4`
gperms=`ls -l $filename|cut -c5-7`
operms=`ls -l $filename|cut -c8-10`

then you can case for the responses you want or whatever.
# 6  
Old 04-16-2008
Or even just run the command once.

Code:
perms=`ls -l "$1" | cut -f1`
case $perms in
  ?r?????????) echo Read for owner;;
esac
case $perms in
 ??w???????) echo Write for owner;;
esac

etcetera. For maintainability, it would be better to loop over user, group, and other, and only case on the first three characters of the value.

Code:
perms=${perms#?}
for role in user group other; do
  case $perms in
    r??*) echo read for $role;;
  esac
  case $perms in
    ?w?*) echo write for $role;;
  esac
  case $perms in
    ??x*) echo execute for $role;;
  esac
  perms=${perms#???}
done

This User Gave Thanks to era For This Post:
# 7  
Old 04-17-2008
thanks but one more question

thanx a lot era and repudi8or..but i ve got a problem in case..
will i be able to get to conditions in one line..
like if a file has rx for the group
i want to have the out put to be read, execute to the user

i know when you put in the case
r?x) echo read execute to the user
will do but it also gives the individual out puts..how do you stop that ???
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question