Thanks, you helped me improve my script's notification system.
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
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.
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:
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.Code:xhost +si:localuser:root
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...
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.
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 theworks.Code:DISPLAY=:0 notify-send ...
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
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.
Or, more spiffy-like:Code:sudo tail -fn0 /var/log/secure | grep --line-buffered "sshd.*Accepted" | while read line; do notify-send -u critical "SSH LOGIN" "$line" done
The script I linked above also prints notifications for failed login attempts. Hope someone finds it useful!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
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
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
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.
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!
Bookmarks