A "tail -f" equivalent command in Powershell to show real time logging

Hello,

Using the powershell command:
Get-Content "Filename" -Wait -Tail 10
showing Real-Time contents of a file in powershell doesn't work.

As example i would like to show Real-Time contents of a systemout.log file in a IBM Websphere Environment.

Using the above command, the shell remain in "listening mode" but nothing happens even if the Systemout.log file changes.

In a unix environment it is enough to type "tail -f filename" and everything work correctly.

Is it possible to use a "tail -f" equivalent command in Powershell to show real time logging?

Thank You in advance.

Fausto.


May 15th, 2015 4:08pm

I just tested this and it seems to be working on my end

Get-Content F:\Testing\test.txt -tail 10 -wait
I modified the file and once saved, it output to my Powershell console.

Free Windows Admin Tool Kit Click here and download it now
May 15th, 2015 4:22pm

I think it depends upon what you mean by 'real time'.  File writes are often buffered in memory and then a chunk is written out.  So a -tail type command will only get what is written on the disk, not what is in memory.  If the log file is not populating rapidly, you could wait some time before log entries, written minutes earlier, were disp

May 15th, 2015 6:18pm

Get-Content F:\Testing\test.txt -tail 1 -wait

If file is locked it will just wait forever.  Call IBM as they did not write the code to work with a tail co

Free Windows Admin Tool Kit Click here and download it now
May 15th, 2015 9:31pm

I mean real-time like is intented in unix world. Using Unix-like command "tail-f" i'm able to read a file while it is modified. The "-Wait" parameter does not work, because the get-content stay in waiting and refresh itself ONLY if the log file is saved.
This is not the concept of "tail -f" command, which reads from the standard output and refresh itself even if the log file is not saved by the application server or so on.

There are many third-party tool which do that, for example Wintail.exe or baretail.exe.
I think that powershell should have this feature embedded.

I hope Microsoft has a solution to my question ;)

Regards.

Fausto.

May 19th, 2015 4:30am

It works but it does not answer to my question.

when You create a text file and you modify that, your "Get-Content F:\Testing\test.txt -tail 10 -wait" command gives a refresh ONLY IF you save the file .txt

If you do not save the file, it stays in waiting forever.

This is not the concept of a log file: a log file is continuosly written but saved only after hours (depends on the log rotate ora something like that in the application server).

Anyway, Thank you for your answer.

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 4:34am

It is not a IBM problem.

There are many third-party tool which do that, for example Wintail.exe or baretail.exe.
I think that powershell should have this feature embedded.

I hope Microsoft has a solution to my question ;)

Regards.

Fausto.

May 19th, 2015 4:35am

It works fine for the rest of us.  If a file is not written to disk it cannot be"tailed" in Unix or inany other system.,  Many utilities do not write to disk oon every update and many files are not open "shared". 

These are all basic software concepts aroung file systems and are identical on Unix and Windows.  If you are having issues understanding how this works and what the restictions are I suggest contacting a systems programmer and discussing how files are manahed in software systems.

You can also post your doubts in the developer forum for a more complete technical answer.

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 6:19am

Sorry but this is not correct.
I repeat the following concept because I think it is not clear.
Using third-party tool like "wintail.exe" and "baretail.exe" I can see the tail of the log file of Websphere Application Server (SystemOut.log) and it is refreshed in real-time while the systemout.log file is written (but not saved because it is saved every n-hours).

I do not guess they work very fine because of a miracle; simply they use at the best the operating system and the concept at the base of logging.

I would remark that I'm able to show the real-time logging (using wintail.exe and baretail.exe) and I'm not here to talk about Microsoft or Unix. I'm here to try to have a great help from someone in order to use powershell and to be not tied up using a third-party tool.

Why should I use "foreign" tool if I have the powerful powershell?

Hope everything is clear now.

Best Regards

Fausto.  

May 19th, 2015 8:44am

Get-Content -tail 10 will wait until 10 lines have been appended before posting.  Use "1".

I have no issues with any file I have tried this with. Perhaps you are missing patches or updates.  Get-Content uses the same API as baretail uses.  The major difference is the Net wrapper that PowerShell uses for most things.

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 9:00am

If I type Get-Content "filename" -tail 1, I see the last modified line in the "filename". If I would see every change in the "filename" file, I should type every second Get-Content "filename" -tail 1 until my fingers become red.

I do not want this.

I desire a command which gives me the possibility to "stay in a listening state" on the log file and see every line changed in real-time (as I said many time before).

From different forums, I see that the "-wait" parameter is used but, as I said many time before, it does not work as I want because the output is refreshed only if the "filename" file is saved.

As I said many time before, in unix, using "tail -f filename" (a very simple command) it is possible to have what I want, that is a tail which is refreshed automatically (without my action) every time "filename" changes even if the file is not saved.

I hope that I have been clear in the explanation of my problem.

If there is not a solution, I will continue using "wintail.exe" but it will be frustrating for me to have not a unix-equivalent command in powershell.

Thank you in advance.

May 19th, 2015 11:04am

You certainly are making this very hard.

Get-Content "filename" -tail 1 -wait

Without the wait you will get only the last line because that is what you asked for.

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 11:08am

I said that I used it.

<<
From different forums, I see that the "-wait" parameter is used but, as I said many time before, it does not work as I want because the output is refreshed only if the "filename" file is saved.

>>

May 19th, 2015 11:10am

I don't have that issue.
Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 11:11am

So if you do not have this issue, the issue does not exist.

Thank you.

May 19th, 2015 11:12am

So if you do not have this issue, the issue does not exist.

Thank you.

That is correct.  You have a system that works odd.  Suspect missing patches.  Do you have all Net updates in place?

We cannot fix your system for you as this is a scripting forum and not a help desk.

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 11:14am

It is the further thing from the term "correct".

I have a system updated to the last patch. Which kind of patch could solve this problem?
A question: f it would be a patch problem, how could wintail.exe work correctly as I want?

the real problem is that you do not understand the problem (maybe my fault).


Thank you.

P.S.

I know this is not a help desk. I wrote on this forum because i thought I could find help from someone more expert than me using powershell.
May 19th, 2015 11:26am

Like I said.  We don't fix-em we just script-em.

There are many optional patches to the Net Framework.  It is also possible to have a broken framework so use the repair tools.

You also need to contact the vendor of the program that generates the log file to be sure that they are opening it as a shared file.  If it is not opened shared-read--deny-none then no tail program can read it.  That I snot a scripting issue but is between you and your vendor.

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 11:38am

I think this is unreal.

I think it is ridicolous that a powershell could not do a thing that a third-party tool like wintail could do.


I will continue using unix tools or wintail.exe.

Anyway, I will waiting for someone else which could give me an answer because I believe in the power of powershell.

thank you for your time and answers even if them did not resolve my question.

Regards.

Fausto.

May 19th, 2015 11:46am

As I posted.  I have not had any issues and I also use both wintail and baretail. I see not difference except for those have more features.
Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 12:12pm

Listen,

are you kidding me or what? What's wrong with me?
As I posted and as I said too much before, you have no problems because you do not understand my problem.

Than, I ask you, please, kindly, to leave this post to other people who would like to help other people.

Which kind of test have you done? Maybe you edited a .txt file and saved it while the Get-content "file.txt" -Tail 1 -Wait is running?
I said that this is not the right test. How many times i should repeat it?

Please. Come on.
I thank you for your precious time lose with me, but the problem is not solved.

Bye.

May 20th, 2015 3:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics