我不知道问题是什么。我很困惑
我正在使用该命令:
crontab -e
Crontab内容:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * /home/myuser/Belgeler/test.sh
(我也这样尝试过:* / 1 * * * * /home/myuser/Belgeler/test.sh每分钟的时间表)
当我在终端上使用时,它运行良好:
/home/myuser/Belgeler/test.sh
test.sh文件在这里:
#!/bin/sh
notify-send -i terminal "Notification test"
我不知道问题是..
我还使用以下代码授予了权限:
chmod +x test.sh
编辑:有趣,但它正在与某些命令,如“ mv(移动)”。但是它不适用于notify-send命令。
您缺少DISPLAY
-variable。将您的脚本更改为
DISPLAY=:0 notify-send -i "Notification test"
当您从自己的环境中运行脚本时,会自动设置许多环境变量。但是,Cron只能使用一组有限的环境变量来运行。
要运行GUI应用程序(包括notify-send
),该DISPLAY
变量必不可少。
如果您有一个DISPLAY
以上的用户(例如,如果有更多用户登录),则DISPLAY
可能不是。DISPLAY=:0
如果您经常有一个以上的用户登录,则可能必须在脚本中包含解析命令信息的内容:
who -u
产生像这样的行:
jacob :0 2016-03-18 08:30 ? 2419 (:0)
如您所见,我DISPLAY
是:0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句