1

A few days ago I asked Is there a way to make tail -F beep?

Now I want to know if there is any way to use *nix utilities, to beep when a tail -F stops returning new lines for a while!

I know, I can write a simple application in any language to do this, but I was curious to know if there is a way to do this just by standard (or semi standard) utils.

The goals is to beep when a file (like a log file) no longer grows.

Ali
  • 6,693
  • 6
  • 32
  • 37

3 Answers3

2
tail -F asdf.log | while true; do if read -t 1 LINE; then echo $LINE; else echo beep; fi; done

(Change the number after -t to the number of seconds of inactivity you want)

Kevin
  • 40,087
  • 16
  • 88
  • 112
cpugeniusmv
  • 2,627
  • 17
  • 25
  • @cupgeniusmv cool! What in heavens name is `read` and why it doesn't have its own man page. Still `read -t` is very cool, I didn't know there is such a thing. – Ali Nov 30 '11 at 17:12
  • By the way I imagine I can pass `$LINE` to `awk` or `sod` if I am interested in further manipulations, but just out of curiosity that would be nice to see if there are other solutions maybe involving `awk` or `sed` without a `while` and `read -t` ! – Ali Nov 30 '11 at 17:14
  • 1
    `read` is a bash builtin function. It's also one of the worst words to search for in the bash man page! :) In the version I have here, it's around line 3350. – cpugeniusmv Nov 30 '11 at 17:18
  • 4
    You can ask `type read` to see what it is. As it is a shell builtin, you can ask `help read` for usage information. – manatwork Nov 30 '11 at 17:28
  • On mac osx 10.7 it's on lines 2978-3006. – Ali Nov 30 '11 at 17:30
  • 3
    `info bash`, then `s` for search, then type "`read'" (backtick, "read", apostrophe). Command names, keywords, and so forth are delimited by a backtick and an apostrophe, which makes them relatively easy to search for. – Keith Thompson Nov 30 '11 at 17:54
2

Use the silence monitor in screen(1). You can set it for a certain period of 'silence' (no input/output) and a visual or audible bell will be sounded.

Arcege
  • 22,287
  • 5
  • 56
  • 64
  • thanks, for my use, it has too problems, 1- it needs for the affected "window" to be sent to background (which I don't want) 2- My screen, does not ring the bell it just displays a line in the message line. – Ali Dec 01 '11 at 03:34
  • 2
    For 2, use the `vbell` command to toggle between visual and audible bell. – Arcege Dec 01 '11 at 05:27
1

Suppose you have a log file called log.txt. If log.txt is not updated for at least 5 seconds, this command will warn the user by a beep sound:

perl -e 'for(;;){$p=$z;$z=`wc -l log.txt`;if ($z==$p) {print "\a";}sleep(5);}'

It's ugly but it works ;)

neuron34
  • 1,256
  • 8
  • 5
  • It is really ugly! But still it works fine, on every descent OS. How did you get to learn this?! – Ali Dec 01 '11 at 03:31