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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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).
Method 2
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
Method 3
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
Method 4
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 Terminalpreferencesadvanced).
Method 5
For anyone else who finds this page, I’m using tcsh and this seems to work:
tail -f changingfile | sed -e 's/.*/& a/'
Don’t ask me what the sed syntax means…
Method 6
You can try konsole which allows alert on new activity (or silence) in any given tab.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0