如何在crontab中指定什么用户运行脚本? [英] How to specify in crontab by what user to run script?

查看:136
本文介绍了如何在crontab中指定什么用户运行脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个crontab作业,根目录下运行,但是给我一些问题。例如,在该cron作业的过程中创建的所有文件夹都在用户root和组root下。
我如何让它在用户www-data和组www-data下运行,所以当我从我的网站运行脚本,我可以操纵这些文件夹和文件?

I have few crontab jobs that run under root, but that gives me some problems. For example all folders created in process of that cron job are under user root and group root. How can i make it to run under user www-data and group www-data so when i run scripts from my website i can manipulate those folders and files?

我的服务器在Ubuntu上运行。

当前crontab作业是:

My server runs on Ubuntu.
Current crontab job is:

*/1 * * * * php5 /var/www/web/includes/crontab/queue_process.php >> /var/www/web/includes/crontab/queue.log 2>&1


推荐答案

不是创建一个以root用户身份运行的crontab,而是为要运行脚本的用户创建一个crontab。在你的情况下, crontab -u www-data -e 将编辑www-data用户的crontab。只需把你的完整命令在那里,并从根用户的crontab中删除它。

Instead of creating a crontab to run as the root user, create a crontab for the user that you want to run the script. In your case, crontab -u www-data -e will edit the crontab for the www-data user. Just put your full command in there and remove it from the root user's crontab.

这篇关于如何在crontab中指定什么用户运行脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆