【发布时间】:2018-08-10 09:00:09
【问题描述】:
我无法从 crontab 运行以下简单脚本:
#!/bin/bash
notify-send "battery.sh working"
该文件的权限为rwxr-xr-x,使用bash battery.sh 和sh battery.sh 中的任何一个命令都可以正常运行。
在我的 crontab 中,我尝试使用 bash 和 sh 运行它,使用绝对路径和本地路径。我当前的 crontab 如下所示:
* * * * * /home/marpangal/battery.sh
* * * * * sh battery.sh
* * * * * bash battery.sh
* * * * * sh /home/marpangal/battery.sh
* * * * * bash /home/marpangal/battery.sh
但是 cron 不执行脚本,并且我没有收到来自 notify-send 的消息。
【问题讨论】:
-
您是否尝试过仅添加文件路径?像这样:
* * * * * /home/marpangal/battery.sh。另外,您的 crontab 是否以您的用户身份运行?因为该组没有文件的执行权限。 -
我添加了文件的路径,例如
* * * * * /home/marpangal/battery.sh。我还为所有人提供了执行权限。但我仍然没有收到来自通知发送的任何消息。我正在使用crontab -e添加 cron。 -
notify-send很可能不在 cron 使用的最小PATH中——有关详细信息和其他常见问题,请参阅 superuser: "crontab and binaries in /usr/local/bin" 和 askubuntu: "Why crontab scripts are not working?"。
标签: bash ubuntu cron notify-send