我需要显示来自cron作业的通知。我的crontab类似于:
$ crontab -l
# m h dom mon dow command
* * * * * Display=:0.0 /usr/bin/notify-send Hey "How are you"我检查了/var/log/syslog,该命令实际上每分钟执行一次,但它没有弹出通知。有人能告诉我为什么吗?
发布于 2013-05-13 18:39:29
我找到了答案:
$ crontab -l
# m h dom mon dow command
* * * * * export DISPLAY=:0.0 && export XAUTHORITY=/home/ravi/.Xauthority && sudo -u ravi /usr/bin/notify-send Hey "How are you"发布于 2018-12-04 01:07:29
我在Ubuntu18.04上使用i3。我解决这个问题的方法是:
* * * * * XDG_RUNTIME_DIR=/run/user/$(id -u) notify-send Hey "this is dog!"
编辑2020:我仍然在Ubuntu 20.04上使用它。
发布于 2014-10-21 09:23:58
在Ubuntu 14.04中,导出显示对我不起作用。下面是我使用的cron脚本,用于当笔记本电脑的电池状态变得太低时关闭虚拟机。行设置DBUS_SESSION_BUS_ADDRESS是最终使警告正确工作的修改。
#!/bin/bash
# if virtual machine is running, monitor power consumption
if pgrep -x vmware-vmx; then
bat_path="/sys/class/power_supply/BAT0/"
if [ -e "$bat_path" ]; then
bat_status=$(cat $bat_path/status)
if [ "$bat_status" == "Discharging" ]; then
bat_current=$(cat $bat_path/capacity)
# halt vm if critical; notify if low
if [ "$bat_current" -lt 10 ]; then
/path/to/vm/shutdown/script
echo "$( date +%Y.%m.%d_%T )" >> "/home/user/Desktop/VM Halt Low Battery"
elif [ "$bat_current" -lt 15 ]; then
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";
notify-send -i "/usr/share/icons/ubuntu-mono-light/status/24/battery-caution.svg" "Virtual machine will halt when battery falls below 10% charge."
fi
fi
fi
fi
exit 0相关的代码行如下:
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";我在这里找到了解决方案:https://askubuntu.com/a/346580/255814
https://stackoverflow.com/questions/16519673
复制相似问题