【问题标题】:Bash script in raspbian runs manually, won't run in cronraspbian 中的 Bash 脚本手动运行,不会在 cron 中运行
【发布时间】:2015-05-27 13:21:11
【问题描述】:

可以这么说,试图把一台小电视变成相框,所以我有一个 Raspberry Pi,我在 /home/pi/scripts/script.sh 有一个 bash 脚本:

#!/bin/sh
sudo /usr/bin/gpicview /home/pi/Downloads/test_5_25.png >> /home/pi/Downloads/test.log

我的 cron 选项卡如下所示: # m h dom mon dow command * * * * * sh /home/pi/scripts/script.sh

我的系统日志显示它正在运行:

May 27 04:32:01 raspberrypi /USR/SBIN/CRON[2999]: (pi) CMD (sh /home/pi/scripts/script.sh

但是 gpicview 没有像我手动运行脚本时那样打开,并且在我的错误日志中显示...

选项解析失败:无法打开显示:

我想可能是权限之类的,但我已尽我所能仔细检查了这些,但无法弄清楚。任何线索将不胜感激!

【问题讨论】:

  • 现在您的 Cron 以 'pi' 用户身份运行。您是否尝试过以 root 身份添加 cron?
  • 运气不好...May 27 04:59:01 raspberrypi /USR/SBIN/CRON[3232]: (root) CMD (sh /home/pi/scripts/script.sh)
  • 是否有任何“显示”参数可以传递给 gpicview?您可以在其手册页中查看它。

标签: bash cron raspberry-pi raspbian raspberry-pi2


【解决方案1】:

您可能需要手动设置显示,即:

* * * * * export DISPLAY=:0 && sh /home/pi/scripts/script.sh

如this article 中所述。

【讨论】:

    猜你喜欢
    • 2019-07-27
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    相关资源
    最近更新 更多