简体   繁体   中英

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 . The permission of user directory is 0777 and owner is ' user@example.com ' that is a FTP user and group is ' www-data '. I need to run a bash script on file upload to perform some tasks after files are uploaded. For that, I need to change the ownership of the directory user. inotify catches the new file creation events in FTP directory. 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. I am running the sh script from root user. The owner of this script is root and it is set to executable mode.

Had the same problem frequently. Add / at the end, it worked for me.

chown -R root:www-data /var/www/html/storage/user/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM