嗨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