You are not logged in.

#1 2011-04-11 18:28:42

hellomynameisphil
Member
From: /home/phil/Vancouver
Registered: 2009-10-02
Posts: 257
Website

[SOLVED]Would be grateful for help with im notification shell script

Hi all,

Playing with finch (a console im client), and haven't found any notification plugins for it that work the way I want.

What I have been doing is using tail to watch the logs. As the logs are in html, I use sed to strip the html tags:

tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* | sed -e 's#<[^>]*>##g'

I would like to use notify-send or dzen2 to create popup windows when the log file changes, but I'm not sure how (I am not an experienced programmer).

This, for example, does not work:

tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* | sed -e 's#<[^>]*>##g' | while read line ; do notify-send "${line}" ; done

Removing sed from the stream above allows notify-send to pop up notifications. How can I have the same happen with sed in there?

Last edited by hellomynameisphil (2011-10-22 17:49:34)

Offline

#2 2011-04-11 21:56:38

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,308

Re: [SOLVED]Would be grateful for help with im notification shell script

I am not an expert, but what if you use 'tee' and pipe the output of tail through both sed and while...done in parallel ?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2011-04-12 02:24:09

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: [SOLVED]Would be grateful for help with im notification shell script

Try this:

while read line
do
    notify-send "$(sed -e 's#<[^>]*>##g' <<< $line)"
done < <(tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* )

Last edited by rockin turtle (2011-04-12 02:25:10)

Offline

#4 2011-04-14 00:38:35

hellomynameisphil
Member
From: /home/phil/Vancouver
Registered: 2009-10-02
Posts: 257
Website

Re: [SOLVED]Would be grateful for help with im notification shell script

rockin turtle wrote:

Try this:

while read line
do
    notify-send "$(sed -e 's#<[^>]*>##g' <<< $line)"
done < <(tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* )

That did it. Thanks!

Offline

#5 2011-04-14 09:59:40

Damnshock
Member
From: Barcelona
Registered: 2006-09-13
Posts: 414

Re: [SOLVED]Would be grateful for help with im notification shell script

hellomynameisphil wrote:
tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* | sed -e 's#<[^>]*>##g' | while read line ; do notify-send "${line}" ; done

Removing sed from the stream above allows notify-send to pop up notifications. How can I have the same happen with sed in there?

The problem here is that sed is buffering its output to improve efficiency in pipes. Try with:

tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* | sed -e 's#<[^>]*>##g' -u  | while read line ; do notify-send "${line}" ; done

And should work as well smile

Regards


My blog: blog.marcdeop.com
Jabber ID: damnshock@jabber.org

Offline

#6 2011-04-15 22:15:02

hellomynameisphil
Member
From: /home/phil/Vancouver
Registered: 2009-10-02
Posts: 257
Website

Re: [SOLVED]Would be grateful for help with im notification shell script

Yes, damnshock, that works as well. Thank you.

Offline

Board footer

Powered by FluxBB