Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: cron + notify send

  1. #1
    Join Date
    Apr 2010
    Beans
    219
    Distro
    Ubuntu 10.04 Lucid Lynx

    cron + notify send

    I can't get cron to work out a notify send.

    Code:
    [jk@Ubuntu /]$ sudo crontab -l
    * * * * * env DISPLAY=:0.0 /home/jk/Scripts/Alarm.sh >> /home/jk/check.log 2>&1
    * * * * *  DISPLAY=:0.0 /home/jk/Scripts/Alarm.sh >> /home/jk/check.log 2>&1
    Cron creates an empty 'check.log' in my home directory but still doesn't display notify-send.

    I've checked the 'notify-send script' manually and it works.

    Code:
    [jk@Ubuntu /]$ cat /home/jk/Scripts/Alarm.sh 
    #!/bin/bash
    DISPLAY=:0.0 /usr/bin/notify-send Blink "Blink 5x" -t 7000

  2. #2
    Join Date
    Mar 2010
    Location
    sudo apt-get upgrade
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: cron + notify send

    I had the same problem before.. and then I enabled X ACL for localhost to connect to GUI applications.

    ~$ xhost +local:
    non-network local connections being added to access control list
    ~$ xhost
    access control enabled, only authorized clients can connect
    LOCAL:
    ...
    Reference:
    https://help.ubuntu.com/community/Cr...20Applications
    I'm the best in what I do!

  3. #3
    Join Date
    Mar 2010
    Location
    sudo apt-get upgrade
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: cron + notify send

    Also, there is no need of "DISPLAY=0.0" in your Alarm.sh, as you'll be giving it from cron.

    & with notify-send "expire time" doesn't work yet. No Matter what you do, that notification will stay on your screen ~10 seconds.

    PS: if you're getting work expire-time somehow.. please let me know.
    I'm the best in what I do!

  4. #4
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: cron + notify send

    also, any reason why you're running this from roots crontab (sudo crontab) rather than your own user's crontab? As root you won't have the correct DBUS_SESSION_BUS_ADDRESS set that you would need to send the notification to your users gnome session, so I don't think your notify-send command will work.

  5. #5
    Join Date
    Apr 2010
    Beans
    219
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: cron + notify send

    Quote Originally Posted by DaithiF View Post
    also, any reason why you're running this from roots crontab (sudo crontab) rather than your own user's crontab? As root you won't have the correct DBUS_SESSION_BUS_ADDRESS set that you would need to send the notification to your users gnome session, so I don't think your notify-send command will work.
    i disabled the 'sudo' command and got it working perfectly, awesome. thanks!

  6. #6
    Join Date
    Apr 2010
    Beans
    219
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: cron + notify send

    Quote Originally Posted by Rushyang View Post
    Also, there is no need of "DISPLAY=0.0" in your Alarm.sh, as you'll be giving it from cron.

    & with notify-send "expire time" doesn't work yet. No Matter what you do, that notification will stay on your screen ~10 seconds.

    PS: if you're getting work expire-time somehow.. please let me know.
    no wonder it stayed a little too long

  7. #7
    Join Date
    Apr 2008
    Location
    Far, far away
    Beans
    2,148
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: cron + notify send

    It is possible to enable the timeout (-t) option but it requires replacing notify-send with a ppa package that a user rebuilt with the fix. I did that and it works. The ppa is leolik

    The all-knowing Ubuntu devs have decided that they don't want to support -t so other than this you'll not see it supported any time soon.

  8. #8
    Join Date
    Mar 2010
    Location
    sudo apt-get upgrade
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: cron + notify send

    Quote Originally Posted by DaithiF View Post
    also, any reason why you're running this from roots crontab (sudo crontab) rather than your own user's crontab? As root you won't have the correct DBUS_SESSION_BUS_ADDRESS set that you would need to send the notification to your users gnome session, so I don't think your notify-send command will work.
    yes, you're right DBUS_SESSION_BUS_ADDRESS variable is unavailable in root environments. But, I wonder notify-send with my root cron is working perfectly... I know this because, This is because I run some cron for regular data backup & kill processes at specific time as root & to notify that task successfully completed, I use notify-send.
    Last edited by Rushyang; April 14th, 2011 at 12:19 PM.
    I'm the best in what I do!

  9. #9
    Join Date
    Mar 2010
    Location
    sudo apt-get upgrade
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: cron + notify send

    I also wonder, is there any way to work with zenity via crons??

    EDIT:
    well, I just simply figured out if we add "DISPLAY=:0.0" line as prefix before calling any GTK+ dialogs (through zenity) even in scripts. They works just fine.
    Last edited by Rushyang; April 23rd, 2011 at 06:49 PM.
    I'm the best in what I do!

  10. #10
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: cron + notify send

    the dbus session variable problem can be gotten around ... ie. even if you are root you can figure out the right value for a logged in user and set that value in your own environment such that notify-send appears on the user's desktop.

    you pgrep for the users nautilus session, or gnome-panel, etc, ie. some process that is sure to running if that user is logged in, then from the pid grab the variable from the /proc/<pid>/environ

    so something like:
    Code:
    pid=$(pgrep -u username nautilus)
    dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//' )
    DBUS_SESSION_BUS_ADDRESS=$dbus

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •