我有一个通过 crontab 运行的 python 程序,并且运行良好。但是,我决定添加通知我它正在做什么的功能,但它突然失败了。它从命令行运行,但是,将其作为 crontab 程序运行会导致它失败
libnotify-Message: Unable to get session bus: /bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
我究竟做错了什么?
编辑 我希望这个程序仍然从 cron 运行,并能够利用通知用户它的工作。有没有办法做到这一点?
编辑 2
我尝试过使用 root 的 crontab,sudo -u esr python script.py
但这也失败了,只是默默地。
编辑3 这是可能的!这是代码。
* * * * * su $user -c "DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(ps -au esr | grep -i "gnome-session" | awk '{ print $1 }')/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//') $(whereis notify-send | awk '{ print $2 }') -u normal -t 20000 \"Hello\" "