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

bourne shell script that shows owner, group and other permissions in a

Status
Not open for further replies.

yy3

Technical User
Nov 7, 2006
2
GB
Hi Everybody,

I have been trying to write a script that takes an argument, the script should determine what permissions the owner,group and other has of the file passed in.

I need your help kindly assist

yy3.

What I have been able to do is as follows

echo -n ''Enter filename''
read file
[-r $owner] $$ R=''Read = yes'' | | R=''Read = no''

I don't know how to proceed if am right.
 
Unfortunately your construct of
[ -r $file ] . . .

only tests the existance of and whether it is readable by the current process (not what the owner permissions are).

The command ls -l $file will tell you what the permissions are for 'owner, group and other'.

I hope that helps.

Mike
 
Assuming you have root privileges then you could do something like
Code:
#!/bin/ksh

abort()
 {
 echo $1
 echo "Usage $0 <username> <file to test>"
 exit 1
 }

[[ $# -eq 2 ]] || abort "no user name and file name passed"
egrep -q "^$1:" /etc/passwd || abort "$1 is not a known user"
[[ -f $2 ]] || abort "$2 does not exist"
su - $1 -c "[[ -r $2 ]] && exit 0 || exit 1" && echo $1 can read $2 || echo $1 unable to read $2

Ceci n'est pas une signature
Columb Healy
 
Ooops - after I replied I saw that you requested a bourne script. Personally, and at the risk of starting a flame war, I'd say use bash or ksh wherever possible.

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top