Advertisement
Guest User

Untitled

a guest
Mar 14th, 2011
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.87 KB | None | 0 0
  1. #!/bin/bash
  2. # whocanwrite <file>
  3. # prints users who can write to file (can  contain duplicates)
  4.  
  5. rights_string=`ls -ld $1 | awk '{print $1}'`
  6. owner_string=`ls -ld $1 | awk '{print $3}'`
  7. group_string=`ls -ld $1 | awk {'print $4'}`
  8.  
  9. those_can_write=""
  10.  
  11. if [ ${rights_string:2:1} = "w" ]
  12. then
  13.     those_can_write=$owner_string
  14. fi
  15.  
  16. if [ ${rights_string:5:1} = "w" ]
  17. then
  18.     group_id=$(cat /etc/group | awk -F: "{if (\$1 == \"$group_string\") print \$3}" )
  19.     initial_group_list=$(cat /etc/passwd | awk -F: "{if (\$4 == \"$group_id\" ) print \$1}" )
  20.     additional_group_list=$(cat /etc/group | awk -F: "{if ( \$1 == \"$group_string\" ) print \$4"} )
  21.     those_can_write="$those_can_write $initial_group_list $additional_group_list"
  22. fi
  23.  
  24. if [ ${rights_string:9:1} = "w" ]
  25. then
  26.    those_can_write=$(cat /etc/passwd | awk -F: "{print \$1}")
  27. fi
  28.  
  29. echo $those_can_write
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement