嗨cron作业:)我想有一个每20分钟,通知一类应用,并决定通过开发一个自己使用Tomboy记事。我读了关于crontab并通过sudo crontab -e
命令设置了一个工作。帮我安装在Ubuntu
*/20 * * * * python /home/phantom/Desktop/alarm.py 2>/home/phantom/Desktop/whatswrong.log
我的Python代码会是这样的:
#!/usr/bin/env python
import dbus, gobject, dbus.glib
# Get the D-Bus session bus
bus = dbus.SessionBus()
# Access the Tomboy D-Bus object
obj = bus.get_object("org.gnome.Tomboy","/org/gnome/Tomboy/RemoteControl")
# Access the Tomboy remote control interface
tomboy = dbus.Interface(obj, "org.gnome.Tomboy.RemoteControl")
# Display the Start Here note
tomboy.DisplayNote(tomboy.FindNote("alert"))
我不知道有关的DBus接口什么,但阅读使用dbus与假小子接口的教程,并想出了以上代码。
当我运行的代码手动我可以打开假小子说明(警报消息),但使用cron我碰到下面的错误,我无法理解。请帮我解决。谢谢:)
Traceback (most recent call last):
File "/home/phantom/Desktop/try.py", line 4, in <module>
bus = dbus.SessionBus()
File "/usr/lib/pymodules/python2.6/dbus/_dbus.py", line 219, in __new__
mainloop=mainloop)
File "/usr/lib/pymodules/python2.6/dbus/_dbus.py", line 108, in __new__
bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 125, in __new__
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: /bin/dbus- launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
如果我看到这个权利,你的cronjob将运行根和根没有一个X11会话。现在,如果我们应该迁移它,它应该在SU还是SF? – Bobby 2011-04-28 14:09:40
@Bobby,我会说SU – dawebber 2011-04-28 15:40:35