fdehanne

fswatch

Jan 2nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.81 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. fswatch -0 --event Created /path/to/my/directory | while read -d '' file; \
  4. do \
  5.     if [[ -e ${file} ]]
  6.     then
  7.         chmod=`stat -f "%p" "${file}"`
  8.         user=`stat -f "%Su" "${file}"`
  9.         group=`stat -f "%Sg" "${file}"`
  10.  
  11.         if [[ -d ${file} ]]
  12.         then
  13.             new_user="xxx";
  14.             new_group="staff";
  15.             new_chmod="770";
  16.         elif [[ -f ${file} ]]
  17.         then
  18.             new_user="xxx";
  19.             new_group="staff";
  20.             new_chmod="775";
  21.         fi
  22.  
  23.         if [[ $user != $new_user || $group != $new_group ]]
  24.         then
  25.             chown $new_user:$new_group "${file}";
  26.         fi
  27.  
  28.         if [[ $chmod != "100$new_chmod" && $chmod != "40$new_chmod" ]]
  29.         then
  30.             chmod $new_chmod "${file}";
  31.         fi
  32.     fi
  33. done
Add Comment
Please, Sign In to add comment