Running a python script from crontab

狂风中的少年 提交于 2019-12-03 20:54:12
* * * * * su esr -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\" "

As per a suggestion, an explanation, unfortunately not mine

You're trying to run a script that requires user resources in an environment where said resources are not available. You will have to strip the script of all references to PyGTK and to the session bus if you want this to work.

I just wanted to mention that the following recipe works for users of the awesome window manager:

*/1 * * * * DBUS_SESSION_BUS_ADDRESS=$(grep -zi DBUS /proc/$(pgrep awesome)/environ | sed -r -e 's/^DBUS_SESSION_BUS_ADDRESS=//') DISPLAY=":0.0" notify-send -t 0 blah blah

You're trying to use GUI (GTK+ library calls) for cron program that has no access to graphical terminal. You need to avoid creating dialogs and windows when you run it from cron.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!