[英]chmod command in Ubuntu works from command line but not from bash script
I have a directory structure /var/www/html/storage/user/job_id
. 我有一个目录结构
/var/www/html/storage/user/job_id
。 The permission of user directory is 0777
and owner is ' user@example.com
' that is a FTP user and group is ' www-data
'. 用户目录的权限为
0777
,所有者为“ user@example.com
”,即FTP用户,组为“ www-data
”。 I need to run a bash script on file upload to perform some tasks after files are uploaded. 我需要在文件上传上运行bash脚本,以在文件上传后执行一些任务。 For that, I need to change the ownership of the directory user.
为此,我需要更改目录用户的所有权。 inotify catches the new file creation events in FTP directory.
inotify捕获FTP目录中的新文件创建事件。 On new file creation event, I call a command to change the ownership of the same directory like
在新文件创建事件中,我调用一个命令来更改同一目录的所有权,例如
chown -R root:www-data /var/www/html/storage/user
But the problem here is if I run this command directly in the terminal, it is executed successfully while it's not changing the ownership when called from a bash file. 但是这里的问题是,如果我直接在终端中运行此命令,则在从bash文件调用时不更改所有权的情况下,它会成功执行。 I am running the sh script from root user.
我正在从root用户运行sh脚本。 The owner of this script is root and it is set to executable mode.
该脚本的所有者为root,并将其设置为可执行模式。
Had the same problem frequently. 经常遇到相同的问题。 Add
/
at the end, it worked for me. 添加
/
最后,它对我有用。
chown -R root:www-data /var/www/html/storage/user/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.