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.

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)

| improve this answer | |
  • @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
  • 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

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.

| improve this answer | |
  • 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 1 '11 at 3:34
  • 2
    For 2, use the vbell command to toggle between visual and audible bell. – Arcege Dec 1 '11 at 5:27

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 ;)

| improve this answer | |
  • It is really ugly! But still it works fine, on every descent OS. How did you get to learn this?! – Ali Dec 1 '11 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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