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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test group permissions 1

Status
Not open for further replies.

soonerhater

Programmer
Nov 16, 2003
4
US
In the Korn shell in unix, of course, -r, -w, & -x are the test operators for user access permissions. how do you test group and global permissions?
 
ls -l of a file will reveal the permissions. You will find 3 sets of rwx, 1st is user, 2nd is group, 3rd is world(global).
If you know your octal code then it's easy to set it using chmod, e.g. chmod 777 filename will set it to rwxrwxrwx, 600 will set it to rwx------, etc.

IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
MS Certified Windblows Rebooter
 
I know how to set it, i need to know how to test it in an if/then statement.
 
You could test for matching patterns....

#----get file permissions
ls -l $FILE | read PERM ETC

#----example tests
if [[ $PERM = -???r????? ]]
then
echo file is group readable
fi
if [[ $PERM = -??????r?? ]]
then
echo file is world readable
fi
if [[ $PERM = -r?x------ ]]
then
echo file is executable by owner only
fi
 
In the Korn shell you can do this...
Code:
[[ -G filename ]] && print "Same effective group as curr process"
Hope this helps.

 
Also...
Code:
[[ -r filename ]] && print "File is readable"
Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top