4

On Linux systems I can

watch -n1 tail /var/log/whatever.log

or

watch -n1 grep somestuff /var/log/whatever.log

To show updates to a log every 1 seconds. On FreeBSD however, the watch command does something else entirely. Who knows a good FreeBSD command for what I'm trying to do? =)

Cory J
  • 1,568
  • 5
  • 19
  • 28

6 Answers6

20

How about this: $ tail -f logfile?

And if you need to grep: $ tail -f logfile | grep foobar.

EEAA
  • 109,363
  • 18
  • 175
  • 245
  • On linux you generally have "tailf" which has the advantage of "not accessing the file when it is not growing". – Shadok Mar 04 '11 at 17:44
8
Port:   gnu-watch-3.2.8
Path:   /usr/ports/misc/gnu-watch
Info:   GNU watch command
Maint:  ehaupt[ woof-woof ]FreeBSD.org
B-deps: 
R-deps: 
WWW:    http://procps.sourceforge.net/
SaveTheRbtz
  • 5,691
  • 4
  • 32
  • 45
4
  • Linux: watch -n 5 tail /var/logfile
  • Freebsd: cmdwatch -n 5 /var/logfile
  • Openbsd: gnuwatch -n 5 /var/logfile

(Install from Ports for the BSDs)

Jenny D
  • 27,780
  • 21
  • 75
  • 114
hc42
  • 41
  • 1
2

You could write a quick shell loop:

while sleep 1; do clear; grep somestuff /var/log/whatever.log | head -n 18; done

fredden
  • 393
  • 1
  • 10
2

If I define your "what I'm trying to do" as "watch changes to a log file", I would suggest rather than using watch that you could just use the "-f" (for "follow") or "-F" option on the tail command, as in tail -f /var/log/whatever.log. The output can also be piped through grep to give you the filtered version you show there. I believe this is also likely to be more efficient than "watch".

Edit: I thought the "follow" option wasn't available on BSD but it appears it is. Must have been thinking of something else that's not there...

Peter Hansen
  • 156
  • 10
  • 2
    There are the same `-f` and `-F` options to [tail](http://www.freebsd.org/cgi/man.cgi?query=tail&sektion=1&apropos=0&manpath=FreeBSD+8.0-RELEASE) on FreeBSD. – Dennis Williamson Apr 14 '10 at 21:38
0

You can use this script for all things that you want to do with watch command.

#!/usr/local/bin/bash
while [ true ]
do
clear
date
echo ------------------------------------
eval "$@"
sleep 2
done

Usage:sh scriptname.sh example:sh scriptname.sh ls -l

HosseinGBI
  • 1,151
  • 1
  • 7
  • 5
  • 2
    You are missing `"` around `$@` and `eval` is not needed. `[ 1 -lt 2 ]` could be replaced with `true`. Your script would be a lot more readable if you used some indentation. – kasperd Oct 14 '15 at 06:50