FirstMan
asked on
A Little Help
i have a quick question
how do i write a script named 'permissions' that 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.
i think that this has something to do with $ chmod 777 [file] who is used to determine the permission of the owne, group and world. i know the 777 will give read, write and execute permissions to all three groups, but i don't know how do write the script.
can someone help me??
how do i write a script named 'permissions' that 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.
i think that this has something to do with $ chmod 777 [file] who is used to determine the permission of the owne, group and world. i know the 777 will give read, write and execute permissions to all three groups, but i don't know how do write the script.
can someone help me??
ASKER
ok i will try explain that further..
i want to write a script called 'permissions' which takes a file as an argument. the script (permissions) should be able to determine which permissions the owner, group and everybody has for the file passed in. after this is completed, the output should resemble this
READ WRITE EXECUTE
------- -------- ------------
owners <usename> yes yes no
group users yes no no
everybody no no no
i want to write a script called 'permissions' which takes a file as an argument. the script (permissions) should be able to determine which permissions the owner, group and everybody has for the file passed in. after this is completed, the output should resemble this
READ WRITE EXECUTE
------- -------- ------------
owners <usename> yes yes no
group users yes no no
everybody no no no
This looks like a homework assignment. Do you have an language requirements?
I just chose bash. perl is another good one. Php is also good, althought a lot of people seem to think it's only good for web usage.
#!/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"
#!/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"
ASKER
Thank you for your assistance. i have done the question but the results are abit funny though.
the output is supposed to resemble this:
READ WRITE EXECUTE
------- -------- ------------
owners adam.adebisi yes yes no
group users yes no no
everybody no no no
But the results resemble this:
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
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
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
m.adebi
m.adebi
m.adebi
m.adebi o t a
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users l -
other r w -
what went wrong? or is it supposed to be look this??
the output is supposed to resemble this:
READ WRITE EXECUTE
------- -------- ------------
owners adam.adebisi yes yes no
group users yes no no
everybody no no no
But the results resemble this:
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
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
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
m.adebi
m.adebi
m.adebi
m.adebi o t a
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users
users l -
other r w -
what went wrong? or is it supposed to be look this??
Nope.
Let me cut and paste this back out and see if it changes.
Let me cut and paste this back out and see if it changes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, what OS are you on? And what version of bash are you running? As well as what is the output of ls -l on that machine.
The machine before(red hat), used ls in a fixed width format, and the ubuntu box at home uses space delimited.
The machine before(red hat), used ls in a fixed width format, and the ubuntu box at home uses space delimited.
ls -l <file> will show you the permissions of the owner, group, and other. As well as show you the owner and the group ownership.
This is an excerpt from http://www.dartmouth.edu/~rc/help/faq/permissions.html
An example of the output produced by 'ls -l' is shown below.
drwx------ 2 richard staff 2048 Jan 2 1997 private
drwxrws--- 2 richard staff 2048 Jan 2 1997 admin
-rw-rw---- 2 richard staff 12040 Aug 20 1996 admin/userinfo
drwxr-xr-x 3 richard user 2048 May 13 09:27 public
Understanding how to read this output is useful to all unix users, but especially people using group access permissions.
Field 1: a set of ten permission flags.
Field 2: link count (don't worry about this)
Field 3: owner of the file
Field 4: associated group for the file
Field 5: size in bytes
Field 6-8: date of last modification (format varies, but always 3 fields)
Field 9: name of file (possibly with path, depending on how ls was called)
To find out the members of a group, you can type id <username> or groups <username>
To find the members of a group, you can cat /etc/group | grep <groupname>
or use ypcat if you are an an NIS environment.
In a single command, you'd want to script that. Is that what you are asking for?