如何在 crontab 中指定哪个用户运行脚本?

编程入门 行业动态 更新时间:2024-10-22 19:24:30
本文介绍了如何在 crontab 中指定哪个用户运行脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 root 下运行的 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.只需将您的完整命令放在那里,然后从 root 用户的 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 中指定哪个用户运行脚本?

本文发布于:2023-10-18 11:08:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504066.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   用户   如何在   crontab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!