Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # whocanwrite <file>
- # prints users who can write to file (can contain duplicates)
- rights_string=`ls -ld $1 | awk '{print $1}'`
- owner_string=`ls -ld $1 | awk '{print $3}'`
- group_string=`ls -ld $1 | awk {'print $4'}`
- those_can_write=""
- if [ ${rights_string:2:1} = "w" ]
- then
- those_can_write=$owner_string
- fi
- if [ ${rights_string:5:1} = "w" ]
- then
- group_id=$(cat /etc/group | awk -F: "{if (\$1 == \"$group_string\") print \$3}" )
- initial_group_list=$(cat /etc/passwd | awk -F: "{if (\$4 == \"$group_id\" ) print \$1}" )
- additional_group_list=$(cat /etc/group | awk -F: "{if ( \$1 == \"$group_string\" ) print \$4"} )
- those_can_write="$those_can_write $initial_group_list $additional_group_list"
- fi
- if [ ${rights_string:9:1} = "w" ]
- then
- those_can_write=$(cat /etc/passwd | awk -F: "{print \$1}")
- fi
- echo $those_can_write[
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement