然后我crontab -e
添加了*/2 * * * * /usr/bin/notify-send "test"
,它应该每 2 分钟发送一次通知,但它不起作用。
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
*/2 * * * * /usr/bin/notify-send "test"
我认为 Cron 作为系统守护进程运行并且不知道您的桌面环境会话,尽管它需要显示通知。您可以编写脚本来发送通知并休眠 2 分钟,然后在后台从您的用户运行它。此外,如果您想要确切的 Cron,您可以创建首先导出桌面标识符的脚本
export DISPLAY=:0
,然后notify-send
从 Cron 调用并调用此脚本,或者简单地将您的 Cron 行替换为*/2 * * * * DISPLAY=:0 /usr/bin/notify-send "test"
.注意 - 对我来说,它在U buntu 16.04 中有效,但在K ubuntu 19.10 中无效。没有在其他系统版本上测试过。