Tuesday, 4 February 2014

Tail in Windows

One of the most useful tools to solve a computer problem is log files. Log files can tell you lots of information about what is happening when a problem occurs. The problem with log files though is that they can often be enormous in size and this creates its own needle in the haystack problem.

The solution as any seasoned *nix admin will tell you is to use tail -f to monitor the log file in real time then attempt to trigger the problem again and see what pops up. If you are lucky the last few lines will relate to your problem and you'll be much wiser about how to solve it.

Now move that process to windows. I've been doing a lot of automation work in windows of late using powershell. Having to solve various problems under windows and lamented the lack of a useful tool like tail. Sure there are stand alone utilities that can perform that function but none seemed to be as simple as tail.

That is until I discovered powershell. Specifically Powershell version 3. Perhaps to appease people like me they have added a '-tail' option to the get-content commandlet. This command simple gets the content of a file. When you combine the tail option with the wait option, you can see anything that's added to the file in real time:

C:> get-content -path "somelogfile.txt" -wait -tail 10

The wait parameter tells get-content to keep waiting for new data to be added whilst the tail parameter says to show the last 10 lines of the file.

In order to get powershell version 3 onto you machine you will need to download an update.

No comments: