gpt4 book ai didi

bash - 如何自动运行 crons?

转载 作者:行者123 更新时间:2023-12-04 19:32:22 25 4
gpt4 key购买 nike

我正在尝试让 crontab 自动运行一个文件,内容如下:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

*/5 * * * * php /path/to/script

我把这个文件叫做 prod.cron进入 /etc/cron.d文件夹,但似乎无法让它自己运行。通过命令行直接运行脚本表明它工作正常,但不确定 cron.d 中的文件是否被自动检测到或者我需要做其他事情来初始化它们?

最佳答案

注意目录/etc/cron.d旨在供软件包使用,应将 crontabs 安装到用户的 crontab 中。话虽如此,请查看以下 Cron Issues :

  1. The script is not having execute permissions. Use chmod a+x to provide permissions.
  2. In the case of php, perl or other scripting language, the path to interpretor or program is not correct. Always provide actual path to the interpretor while defining command to run in cron. To find out where the program is located, use whereis command. For e.g. for php, whereis php. for perl, whereis php, etc.
  3. The environment variables required to run the script are unavailable. The cron doesn't use the same environment of a user. It uses its own environment while running the commands. So the variables defined in .login or .profile are not visible to him. The most common issue is related to PATH variable which is not similar.

关于bash - 如何自动运行 crons?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13845819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com