Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29

Thread: Notify-send HOWTO

  1. #11
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Notify-send HOWTO

    Thanks, you helped me improve my script's notification system.
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

  2. #12
    Join Date
    May 2010
    Beans
    27
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Notify-send HOWTO

    Btw, if anyone is interested, after Karmic(or jaunty, I'm not sure) -t timeout parameter is broken.

    Lately a guy named Sukochev Roman [leolik] has been working on notify-osd a lot!
    ThanX to him, now we have a pretty customizable notifications!
    He has fixed the timeout issue as well!

    Here's an article from webupd8 on how to customize the messages:
    http://www.webupd8.org/2010/05/final...ze-notify.html

    * Edit:

    If Your notify bubbles flicker on fade in/out --> disable "Fading Windows" in Compiz 'Effects' group...
    Last edited by DrAcid; October 14th, 2010 at 01:17 AM.

  3. #13
    Join Date
    Sep 2010
    Beans
    13

    Re: Notify-send HOWTO

    Hi,
    I have successfully used notify-send in an interactive shell and in scripts.

    But if an script is started via cron, notify-send does not work.

    Any hints?

  4. #14
    Join Date
    Nov 2010
    Beans
    2

    Re: Notify-send HOWTO

    Quote Originally Posted by averlon View Post
    Hi,
    I have successfully used notify-send in an interactive shell and in scripts.

    But if an script is started via cron, notify-send does not work.

    Any hints?
    I'm a RHEL user, so paths might be different in Ubuntu.

    You need to allow local root user to display to the current X session. Create a new file /etc/X11/xinit/xinitrc.d/localroot.sh, containing the command:
    Code:
    xhost +si:localuser:root
    When X starts next time, this new script will be sourced from the script /etc/X11/xinit/xinitrc-common. You can do it to a running session by having the session owner (whoever logged in) type the full xhost command exactly as above.

    Now your cron command can say:
    Code:
    DISPLAY=:0  notify-send ...
    Last edited by cream wobbly; June 14th, 2011 at 08:41 PM. Reason: Better xhost command; how to that display...

  5. #15
    Join Date
    Sep 2010
    Beans
    13

    Re: Notify-send HOWTO

    Hi cream wobbly,
    thanks for the reply.
    although ubuntu seems to have a different file structure, since /etc/X11/xinit/xinitrc.d does not exist.

    I am not sure how to setup it here but I will find the way through now.

    Thanks again for your good help.

  6. #16
    Join Date
    Sep 2010
    Beans
    13

    Re: Notify-send HOWTO

    Hi,
    so far it was not possible for me to identify the path where to make the appropriate changes in ubuntu.

    When I enter the xhost-command in a terminal window the cron-job using the
    Code:
    DISPLAY=:0  notify-send ...
    works.

    If i enter the xhost command and the notify-send inside the cron-job, although the job is run as root, it does not work.

    Could you give me a hint where to search and find out what file structure in ubuntu is according to the file structure you reported from RHEL.
    Thanks

  7. #17
    Join Date
    Dec 2011
    Beans
    3

    Lightbulb Re: Notify-send HOWTO

    Quote Originally Posted by sossanator View Post
    Does anyone know the code if i want it to notify me if someone logs in like via ssh?
    I'm a little late, but... The question inspired me to write a bash script to do just that. You can get it here, at my github. (Or here, for direct-download.)

    But here's the simple answer: What you need is something like this.
    Code:
    sudo tail -fn0 /var/log/secure  |
      grep --line-buffered "sshd.*Accepted" |
        while read line; do
          notify-send -u critical "SSH LOGIN" "$line"
        done
    Or, more spiffy-like:
    Code:
    #WARNING: The following uses some special BASH features, meaning, it won't work in dash.
    
    sudo tail -fn0 /var/log/secure |
      grep --line-buffered 'sshd.*Accepted' |
        while read line; do
          timestamp=${line/ $(hostname)*/}
          ip=${line#*from }; ip=${ip% port*}
          msg=${line#*]: }
          notify-send -u critical "sshd: Session initiated by $ip" "[$timestamp]\n$msg"
        done
    The script I linked above also prints notifications for failed login attempts. Hope someone finds it useful!

    Edit: In my sleep-deprived stupor I forgot to link the screenshots I took. Here's two. The rest are at http://b19.org/linux/notify_sshd/.



    Last edited by ryran; December 19th, 2011 at 03:19 AM. Reason: screenshots

  8. #18
    Join Date
    Oct 2009
    Beans
    10

    Re: Notify-send HOWTO

    Appreciate, ryran, works great!!
    (in my k-ubuntu release Oneiric, just changing /var/log/secure by /var/log/auth.log)

    Thanks!
    Last edited by mohave; December 6th, 2011 at 02:57 PM. Reason: misspelling

  9. #19
    Join Date
    Dec 2011
    Beans
    3

    Smile Re: Notify-send HOWTO

    Updated the script I linked in my previous comment. Same link. It worked fine before, but error-handling and cleanup is quite better now (e.g., if you execute it multiple times, it doesn't leave any orphaned tail processes hanging about), and I took into account the whole /var/log/secure VS /var/log/auth.log thing. (THANKS mohave!)
    Last edited by ryran; December 19th, 2011 at 03:21 AM.

  10. #20
    Join Date
    Dec 2011
    Beans
    3

    Smile Re: Notify-send HOWTO

    WOW! My previous post was only a week ago?! Man, since then I've learned a whole new programming language...

    In any case, I almost completely rewrote the script from before (edited the link). Still BASH, but now it's called tail2notify. It is much more generic (takes parameters to pass to tail & grep); however, it can still meet the original goal of notifications on ssh logins. Peace!

Page 2 of 3 FirstFirst 123 LastLast

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
  •