简体   繁体   中英

cron job as a different user?

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.

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.

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

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