We help IT Professionals succeed at work.

New podcast episode! Our very own Community Manager, Rob Jurd, gives his insight on the value of an online community. Listen Now!

x

permissions problem

FirstMan
FirstMan asked
on
254 Views
Last Modified: 2010-04-21
My Question

I want to create a shell script called 'permissions' which takes a file as an argument. The script should be able to determine what permissions the owner, group and everybody has for the file passed in.

The output of this script should resemble this:

                                            READ WRITE EXECUTE
OWNER ADAM.ADEBISI         YES     YES       NO
GROUP USERS                      YES      NO       NO
EVERYBODY                          NO       NO       NO

so far i have done this:

#!/bin/bash

perm=$(ls -l $1 | cut -f1 -d" ")
group=$(ls -l $1 | cut -b26-32 )
owner=$(ls -l $1 | cut  -b17-23)
or=$(echo $perm | cut -b2)
ow=$(echo $perm | cut -b3)
ox=$(echo $perm | cut -b4)
gr=$(echo $perm | cut -b5)
gw=$(echo $perm | cut -b6)
gx=$(echo $perm | cut -b7)
er=$(echo $perm | cut -b8)
ew=$(echo $perm | cut -b9)
ex=$(echo $perm | cut -b10)

echo "For file: $1"
echo -e "\t\tREAD\tWRITE\tEXEC"
echo -e "\t\t----\t-----\t----"

echo -e "$owner\t\t$or\t$ow\t$ox"
echo -e "$group\t\t$gr\t$gw\t$gx"
echo -e "other\t\t$er\t$ew\t$ex"

but the output is not what i predicted

For file:
                READ    WRITE   EXEC
                ----    -----   ----

m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi
m.adebi

where am i going wrong?
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
no, not homework i just need some help. the script runs but the output is not shown correctly. am i missing something from the script??if so, what??

Commented:
It nearly works for me - you'll have to trace what is happening in your case. I added the following lines:

echo perm=$perm
echo group=$group
echo owner=$owner

You may wish to deal with the case of no parameter ($1) being passed, in which "ls -l" is run without parameter - your cuts will look at the first line, which in my system is a total number of files displayed. The other case is a wildcard (eg '*').
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.