1

I am trying to change group and owner (from root to www-data)for a directory at each 5 min interval.

So I have set a cron on root user like `

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

But it's not working .

Kindly help me out.

Thanks in advance.

Sam
  • 1,033
  • 3
  • 16
  • 25

1 Answers1

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

Next instead of 0,5 * * * * as your cron frequency, run it using */5 * * * *

Finally, 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
*/5 * * * * /bin/chown -R www-data:www-data /var/www/pdf/
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186