Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to make tail -F or less beep (ring the bell in a terminal) when new data comes in (a new line is added to the file). Or is there any other unix utility to do this on a linux or mac.

share|improve this question
add comment

5 Answers

up vote 10 down vote accepted

An idea migth be to pipe the output of tail through sed and replace the newline with bell/newline.

But there is propably an easier solution if you use tail within an x-window. There your can execute an action when the content of the window changes (flicker, bell, whatever).

share|improve this answer
4  
Don't replace the newline, add it at the end of the line. –  Kevin Nov 23 '11 at 19:42
    
@Nils, this sed Idea is brilliant but I don't know enough 'sed' to make it work, it looks like I cant capture newlines in the regexpt the usual way (that I am used to), I guess I need to tell sed dont interpret the incoming stream line by line. –  Ali Nov 23 '11 at 20:13
1  
@Ali Indeed, sed acts line by line and you don't directly see the newlines. sed -e $'s/$/\a/' adds a $'\a' (bell character in ksh/bash/zsh syntax) at the end of each line. –  Gilles Nov 23 '11 at 20:35
    
Thanks @Gilles , worked like a charm (on a mac too)! sed regexpt is a bit odd to my naive eyes. –  Ali Nov 23 '11 at 20:38
    
@Gilles: Note that the $'...' syntax is not universal. For example, [t]csh doesn't support it. –  Keith Thompson Nov 23 '11 at 21:13
show 1 more comment

if you use GNU screen, you can set it to "watch" the window with the tail, and it will alert you in your status bar, or by your termcap's defined bell, that there is new output in that window.

http://www.gnu.org/software/screen/manual/html%5Fnode/Monitor.html#Monitor


edit: just had to add this, since you mentioned mac os x

just for fun, if you were looking for something in particular, you can use Mac OS X's say command to read you the file you're watching. just get the logtail command, from:

http://www.hmug.org/pub/MacOS_X/BSD/Administration/Log/logcheck/

And use it in a script like:

#!/bin/bash

file=$1
offset=$(basename "$1")

# while true... let this thing run until it's killed...
while true; do
    output=$(/usr/local/bin/logtail $file .${offset}.offset)
    if [ ! -z "$output" ]; then

        # print the output and say ding
        echo "$output" && say ding
        # to have the file read aloud to you, uncomment the following:
        say "$output"

        fi
    # recheck every 5 seconds
    sleep 5
done
share|improve this answer
    
Thanks @Tim, screen , shows and alert (I guess I can make it ring the bell as well) ONLY ONCE. Not for every new event that happens (not for every new line that is available) –  Ali Nov 23 '11 at 20:11
1  
i added an example for mac that could read the file to you. you could change that to work for linux by installing the linux version of logtail, and using the beep command, instead of say. –  Tim Kennedy Nov 23 '11 at 20:29
    
cool! That is creative, although in my case I am using the beep to be able to monitor a log file without looking at screen. And the actual beep may be better than a voice. –  Ali Nov 23 '11 at 20:40
1  
Can also use screen's exec command to do it as well. The example in the manpage is !:sed -n s/.*Error.*/\007/p which will send a bell each time "Error" is displayed in that window. –  Arcege Nov 24 '11 at 2:57
add comment

You could use multitail. It is an enhanced tail that supports command execution on regular expression match.

E.g. the following command plays a sound and opens an xmessage window each time a martian source packet is logged.

multitail -ex "martian source" "play beep.wav; xmessage " -i /var/log/messages
share|improve this answer
add comment

Just for the record, as @Nils suggested I am using sed to add a bell to each line.

The sed line provided by @Gilles

sed -e $'s/$/\a/' 

works on my mac (I enabled "audible bell" and "visual bell" in my Terminal\preferences\advanced).

share|improve this answer
    
Of note is that $'...' escape sequences are a Bash-only thing. –  amphetamachine Nov 24 '11 at 4:12
    
@amphetamachine thanks, while I am a bash user myself, it would be nice if you or others can add versions that would work on other shells as well. –  Ali Nov 24 '11 at 4:21
    
I'm also a bash user, but I'm slowly learning what will and won't work in other shells. –  amphetamachine Nov 24 '11 at 6:44
add comment

You can try konsole which allows alert on new activity (or silence) in any given tab.

share|improve this answer
    
I imagine konsole would be like screen it alerts once, while I need to receive an alert for every new line. –  Ali Nov 24 '11 at 2:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.