?
Solved

permissions problem

Posted on 2007-10-06
3
Medium Priority
?
243 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?
0
Comment
Question by:FirstMan
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
sjm_ee earned 1500 total points
ID: 20028198
Homework? Don't rely on the output of "ls" to be where you think it is - there are many variations in what "ls" might output. If you have options, it would be much easier to do this in a few lines of C. If you must use a shell script, then find out of your "find" supports "-printf". This will give you some control over the information you wish to processs.
0
 

Author Comment

by:FirstMan
ID: 20028343
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??
0
 
LVL 14

Expert Comment

by:sjm_ee
ID: 20071592
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 '*').
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question