CRON - chown and chgrp to a directory from root user to www-data

这一生的挚爱 提交于 2019-12-11 10:02:02

问题


I am trying to change group and owner (from root to www-data) for a directory.

So I have set a cron on root which looks like this:

 0,5 * * * *   sudo /bin/chown -R www-data /var/www/pdf/ && sudo /bin/chgrp -R www-data /var/www/pdf/

But unfortunately it's not working. Can anyone please help me?


回答1:


0,5 * * * * sudo /bin/chown -R www-data /var/www/pdf/ && sudo /bin/chgrp -R www-data /var/www/pdf/

First off, the chgrp is redundant, you can manage the same with the chown command itself.

So instead of doing sudo /bin/chown -R www-data /var/www/pdf/ && sudo /bin/chgrp -R www-data /var/www/pdf/, you can do sudo /bin/chown -R www-data:www-data /var/www/pdf

Now, instead of adding cron to a user's crontab with sudo / to systemwide cron using /etc/cron.d, add it to the root user's crontab using

sudo crontab -e
1,5 * * * * /bin/chown -R www-data:www-data /var/www/pdf/


来源:https://stackoverflow.com/questions/19831958/cron-chown-and-chgrp-to-a-directory-from-root-user-to-www-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!