作为不同用户的cron工作?

I need to call a script via curl in one of my cron jobs. The script needs write access to the web root. Apache doesn't have write access to my web root. How can I execute the cron job as a different user? Thanks.

You can use group permissions.

Create a group that will have write access to that directory.

groupadd web

Add yourself and apache to the new web group

useradd -G apache web

Change the document root's ownership permissions to belong to the new web group

chown -R you:web /path/to/docroot

Set the docroot writable

chmod a+w /path/to/docroot

No matter how you go about this, you need an account (the more restricted, the better) that has write access to the web root. This seems obvious, I know. Next, log in as that user and create the cron job. If you have root:

$ su
# su -u thisotheruser
$ crontab -e

and create the cron job. A couple exits later, and you're all set.