Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have following python script, and want to run it with cron so that every minute cron will popup a message.

#!/usr/bin/python
# -*- coding: utf-8 -*-

import gtk.gdk
import pynotify
import random

m=[]
m.append("test1")
m.append("test2")
m.append("test3")

n = pynotify.Notification(random.choice(m))
n.set_hint('x', gtk.gdk.screen_width()/2.)
n.set_hint('y', gtk.gdk.screen_height()/2.)
n.show()

This is my cron script:

* * * * * export DISPLAY=:0.0 && /home/user/scripts/notifications.py >/dev/null 2>&1

Unfortunately nothing happens. Can you help please?

share|improve this question

In case anyone else is wondering. I had to export DISPLAY and XAUTHORITY

I'm running this script in cron:

export XAUTHORITY=/home/user/.Xauthority
export DISPLAY=:0
python ~/notifications.py
share|improve this answer
    
I had similar problems with a script that just need info from GNOME via the X session vars. Truly truly annoying stuff. – songei2f Jun 15 '11 at 15:00

From this thread at Ubuntuforums, you're possibly running into xauth problems. X tends to be paranoid about giving display/input access to outside processes, even from the same user.

In an X terminal window, type: xhost local:$USER and see if your cron job works. If so, add that command to your ~/.bashrc file and the fix should persist.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.