我在apache服务器上有几个vhost,一些开发人员分别处理它们。我只想让他们访问他们的网站。由于daemon超越了对站点内创建的任何文件的访问权限,我创建了一个带有inotifywait的脚本,以授予对已更改/创建的文件的权限,但它只适用于单个站点,而为其他vhost复制脚本看起来并不是一个很好的解决方案。
#!/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
有人知道如何解决多个文件夹和开发人员的问题吗?(例如我有3个网站:wordpress、wordpress2和wordpress3)。
谢谢您。
最佳答案
以下代码有效。它检查特定文件夹是否有更改,如果发生更改,则执行相关操作(chown):
#!/bin/bash
wordpressDir="/opt/bitnami/apps/wordpress/htdocs"
wordpress="copyme"
phpDir="/opt/bitnami/apps/phpmyadmin"
phpuser="phpme"
inotifywait -m -r --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -s -q -e create,modify,move "${wordpressDir}" "${phpDir}" |
while read date time dir file; do
FILECHANGE=${dir}${file}
if [[ "$dir" == *"$wordpressDir"* ]]; then
#Change ownership of file
chown $wordpress:$wordpress "$FILECHANGE"
fi
if [[ "$dir" == *"$phpDir"* ]]; then
#Change ownership of file
chown $phpuser:$phpuser "$FILECHANGE"
fi
#Change permissions of file
chmod 755 "$FILECHANGE"
done