Advertisement
chatchai_j

can-user-access-dir

Sep 4th, 2020
1,321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.46 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. [ "`id -u`" != 0 ] && echo "Must be root to run this script" && exit -1
  4. [ -z "$2" -o "$3" ] && echo "Usage: $0 user directory" && exit -1
  5.  
  6. USER="$1"
  7. DIR="$2"
  8.  
  9. id "$USER" >& /dev/null || {
  10.     echo "User '$USER' not exist";
  11.     exit -1;
  12. }
  13.  
  14. [ ! -d "$DIR" ] && echo "Directory '$DIR' not exist" && exit -1
  15.  
  16. sudo -u "$USER" test -d "${DIR}/."
  17.  
  18. if [ "$?" != 0 ]; then
  19.     echo "FAILED: $USER -> $DIR"
  20.     exit 1
  21. else
  22.     echo "OK: $USER -> $DIR"
  23.     exit 0
  24. fi
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement