Link to home
Create AccountLog in
Avatar of FirstMan
FirstMan

asked on

permissions script help

Hi,

I have a question that Im having difficulty with and require assistance. I want to write a simple shell script that holds a file as an argument. The main purpose of the script is to determine what permissions the owner, group and everybody has for the file passed in.

I have try the following script, which is not 100% successful though i feel that im on the right track.

#!/bin/bash

perm=$(ls -l $1 | cut -f1 -d" ")
group=$(ls -l $1 | cut -f4 -d" " )
owner=$(ls -l $1 | cut  -f3 -d" ")
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 so good

the desired output should look like this

                                            READ WRITE EXECUTE
OWNER JAMES.TAYLOR         YES     YES        NO
GROUP USERS                      YES      NO        NO
EVERYBODY                           NO      NO        NO

anyone assistance for this question??

ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account