gpt4 book ai didi

bash - 运行 cronjob 时权限被拒绝

转载 作者:行者123 更新时间:2023-12-04 19:01:28 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Permission denied with bash.sh to run cron

(5 个回答)


1年前关闭。




我有一个计划每 4 分钟运行一次的 cronjob。Cron 运行正常,但无法执行它应该运行的 .sh 文件。Cron 规则如下:

*/15 * * * * cd /var/www/html/etl_project && ./run_etl_incomplete.sh >> /var/www/html/etl_project/cron_log.txt 2>&1

在 cron_log.txt 我收到以下权限被拒绝错误:
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied
/bin/sh: 1: ./run_etl_incomplete.sh: Permission denied

最佳答案

我假设它是您自己用于此 cron 的个人用户,它没有执行该文件的权限。也许该文件是作为 root 用户或其他用户创建的,因此未设置凭据以允许您的用户执行。

首先 - 尝试检查文件上设置了哪些权限

ls -l /var/www/html/etl_project/ | grep run_etl_incomplete.sh

检查输出以查看谁是所有者和组以及设置了哪些权限。

要使文件可执行 -
chmod +x /var/www/html/etl_project/run_etl_incomplete.sh

仅当您首先具有正确的权限(例如,如果您的用户是该组的一部分)来修改文件时,这才有效。
一旦文件成为可执行文件,您的 cron 将运行。

关于bash - 运行 cronjob 时权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44445024/

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