Today something very small, and yet very useful. When you debug something, in linux, more often than not you will have to take a look at some kind of log file.
First suggestion: use many terminal windows. This may seem trivial, but I never thought to open more putty (www.putty.org) sessions with the same user to the same server until I read this possibility in a System Administrator book (which book? Time Management for System Administrator - Amazon). Then my life changed, I'm much faster than before to debug, script and configure.
One of the thing that anyway that slow me down was to watch log files. Usual procedure was to open a new terminal, open a log file, watch the last lines; then quit the editor, reopen the file, watch the last lines. Every time for every change.
Then I found in some blog this magic command:
tail -f /path/to/file
What does it do? Well, it puts in real time on you screen all the lines added to your log file. Specifically,
tail -f output appended data as the file grows;
and
With --follow (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end
This means that you can change for example your ssh config file, try to access in ssh and instantly see on screen why you can't log in! That's cool!
But let's look at the second definition: tail -f follows the file descriptor. What does it mean? It means that it follows the same file even if it's moved or renamed. That's cool, but it has some disadvantaged. For example, if you have a process that moves and/or renames log files when they reach a certain size, then create a new log file, you wont't see the last logs after the move/rename. Manual says that you need to specify the file name in the form tail --follow=filename /path/to/filename
Without options, tail outputs the last 10 lines of the given file. Indicating -n N it outputs the last N lines.
For the complete list of options, see tail(1) - Manual.
That's it. A simple thing, that can ease much of you debugging time. I hope you'll find it useful!
REFERENCES
- tail(1) - Manual.
- www.putty.org - one of the best (in my opinion) remote terminal in the world.
- Time Management for System Administrator - Amazon - I really suggest you to read this book, especially if you are new in system adminstration
Labels: bash, linux, ubuntu