5

I am trying to get cron to provide a screen alert when it spots a particular situation. I know the script is executed each minute but it will not display on the screen.

script executed is:

DISPLAY=:0.0 /usr/bin/notify-send -t 1000 Test "This is a test"

Running Gnome from the Mandriva distribution.

Any ideas?

1

2 Answers 2

5

Is this your user's crontab, not root's crontab?

I'd suggest that, at least for debugging, you create a script as John T describes:

* * * * * /path/to/script.sh

Here's what the script might look like:

#!/bin/bash
{
    echo "trying to notify at $(date)"
    DISPLAY=:0.0 /usr/bin/notify-send -t 1000 Test "This is a test"
    echo "finished notify at $(date)"
} > /path/to/your-notify-debug.log 2>&1

Note that there's no ":" before DISPLAY, as you seem to have in your question. Be sure to make this script executable (chmod +x /path/to/script.sh) and let cron try to run it a few times. Then examine what was written to the logfile.

3

You need to be able to connect to the DBUS user session bus. This needs to be the session bus not the system bus. You can find that by doing a

set | grep DBUS_SESSION_BUS_ADDRESS

then in your script you need to have

export DBUS_SESSION_BUS_ADDRESS={whatever it is}

then do your notify-send

Since the session bus changes every time you login, you might want to add something to your login scripts to write the DBUS_SESSION_BUS_ADDRESS to a file so your script can read that in and export that.

1
  • 2
    It may have already been saved to a file. Try using this at the start of your script: if [[ -z "$DBUS_SESSION_BUS_ADDRESS" ]]; then source "$HOME/.dbus/session-bus"/*-0 && export DBUS_SESSION_BUS_ADDRESS; fi
    – dubiousjim
    Feb 28, 2010 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.