Watch Multiple Logs in a Single Terminal

This post was written by Nick Gauthier. Read other posts by Nick Gauthier.

Have you ever opened 4 terminal windows, SSHed each one into a server, and ran tail on all of them to watch 4 log files?

Have you ever had a terminal window open whose sole purpose was to run “tail my_log” over and over again to look at the output of a file?

It’s a pain, isn’t it?

Introducing “Watch Me” a simple ruby script that allows you to watch multiple log files simultaneously.

go from this:

Before Watch Me

Using multiple terminals to watch logs

to this:

Using WatchMe to watch logs

Using WatchMe to watch logs

First, get Watch Me from github.

Then, try out the example by following these instructions:

1) Open 3 terminal windows in the watch_me directory
2) In the first terminal, run:
$ ./examples/rander.rb > rander.1.log
3) In the second terminal, run:
$ ./examples/rander.rb > rander.2.log
4) In the third terminal, run:
$ ./watch_me.rb rander.1.log rander.2.log

You can customize the behavior with the “r” and “l” flags.

./watch_me.rb -l 60 -r 1 file1 file2

Will use 60 terminal lines and refresh every 1 second. This lets you see even more of your files, and see it in near real-time.

Enjoy.

About the author: Nick has been a developer at SmartLogic Solutions since January of 2008.

Tags: , ,

2 Responses to “Watch Multiple Logs in a Single Terminal”

  1. You should definitely check out GNU Screen. It’s documentation is a bit difficult to wade through, but this would be a good use case for using split windows within screen. (and besides that, screen is an essential part of any frequent terminal user’s toolkit.)

  2. Hey Nicholas,

    I love screen, but it still requires you to run the command 4 times instead of just one command, and it requires a lot more keystrokes to set up.

    This way lets you change quickly which files you’re accessing by just typing them in the command.

    Also to pre-empt another expected comment, yes I know about tail -f.

Leave a Reply