I have a few vhosts on apache server and a few developers working on them separately. I want to give them access to their site only. Since daemon overtakes access on any file that is created within site, I created a script with inotifywait to grant permission on a file that is changed/created, but it only works for a single site and duplicating script for other vhosts doesn't look like an elegant solution.
#!/bin/sh
monitorDir="/opt/bitnami/apps/wordpress/htdocs"
inotifywait -m -r --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -q -e create,modify,move "${monitorDir}" | while read date time dir file; do
FILECHANGE=${dir}${file}
#Change ownership of file
chown wpdev1:wpdev1 "$FILECHANGE"
#Change permissions of file
chmod 755 "$FILECHANGE"
done
Does anyone have an idea how this can be solved for multiple folders and developers? (for instance I have 3 websites: wordpress, wordpress2 and wordpress3). Thank you.
The following code works. It checks for certain folder for changes and does relevant actions (chown), if changes occur: