简体   繁体   English

Ubuntu中的chmod命令可从命令行运行,但不能从bash脚本运行

[英]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.

相关问题 Debian bash脚本在命令行中运行良好; 在crontab中失败 - Debian bash script works fine from command line; fails in crontab 查找命令可从命令行运行,但不能在脚本中运行 - Find command works from command line but not in a script 如何在Linux(ubuntu)中从bash脚本运行exec bash命令? - How to run exec bash command from the bash script in Linux (ubuntu)? 命令可以从命令行运行,但不能从shell脚本运行 - Command works from command line but not from shell script Bash 脚本可以从命令行调用,但不能从 Python 脚本调用 - Bash script can be called from command line, but not from Python script $MACHTYPE (ubuntu-Bash) 在命令行上工作 - 不是在运行脚本时 - $MACHTYPE (ubuntu-Bash) works on the command line- not when running the script 在tcsh shell脚本中从bash获取最后一个命令行条目 - get last command line entry from bash in a tcsh shell script 从命令行参数使用bash脚本复制多个文件? - Copy multiple files with bash script from command line arguments? 从另一个 bash 脚本运行名为 arguments 的命令行 - Run command line with named arguments from another bash script node.js脚本在命令行下运行但不是从浏览器中运行? - node.js script works off command line but not from browser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM