Results 1 to 5 of 5
Hi,
I am new to this forums and since my question doesn't seem to be tightly linked to a certain distro I post it here (feel free to move it, ...
- 10-21-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 2
Getting the last 20-50 Kb of the console output
Hi,
I am new to this forums and since my question doesn't seem to be tightly linked to a certain distro I post it here (feel free to move it, if it is misplaced here).
So, I have the following programm: I have a console Java application which is supposed to run for, let's say, unlimited time. This application collects some data from external devices and writes this data to a binary file, whereas the log data is automatically written to console (cout). Now there is a problem that the prog just terminated 48-55 hours after start and I need the last 40-50 Kb of its log, which is normally written to console, to analyze. The log is very verbose, so 48 hours will results in 40-50 Gb text file I absolutely don't have space for. Is there a way to redirect the output of this application to the file so that only the last 40-50 Kb of the text remains and the file is being rewritten? Or maybe there is another solution?
Greetings,
Alexander.
- 10-21-2008 #2
You could create a queue structure (FIFO) big enough to handle the amount of data you want to keep. As soon as it's full as you allocate memory for, the next piece of data in will push out the first token of data that you put in.
So for example, you could have some sort of queue object called dataLog. Then, every time you write data to cout, also push that data into the queue. After pushing the data, check the size of dataLog and if it's bigger than what you want to keep, just dataLog.remove().Registered Linux User: #479567
Asking a question? Read this page first.
Now... sudo make me a sandwich.
ratiocinativeroot.blogspot.com
- 10-21-2008 #3
Oh, and by the way... welcome to the forums!
Registered Linux User: #479567
Asking a question? Read this page first.
Now... sudo make me a sandwich.
ratiocinativeroot.blogspot.com
- 10-21-2008 #4Just Joined!
- Join Date
- Oct 2008
- Posts
- 2
Hi, Daniel,
thank you for welcoming me here!
I understand your idea, but I do not want to modify the original Java Application which is running, I just need to get the last several Kb of its log. The simplest solution would be just to have it run on console and to copy the last line from the console -- unfortunately this Java Application is running on en embedded ARM machine I connect via the serial connection (COM1) -- so, whenever I reconnect to the machine which already stopped running the application I do not have any access to the latest line written to the console.
Maybe there is a way to get these last lines from the console??
Alexander.
- 10-21-2008 #5
Do you have access to the terminal before or after you run the application? You could do something like this:
That may not be exactly right, but the idea is to have log file where your last 40 to 50 kB will end up. Every minute, you take the last 50000 bytes from that file and replace logfile with that (you can't directly say tail logfile > logfile because logfile will end up empty). You don't really want to see the output from watch though, so we just send the output to /dev/null. Then we run the java application and let the output be put into this logfile.Code:$ touch logfile $ touch tmpfile $ watch -n 60 'tail -c 50000 logfile > tmpfile; cat tmpfile > logfile' &> /dev/null & $ java myapplication.java > logfile
Does that make sense, and did I even code this right? =)Registered Linux User: #479567
Asking a question? Read this page first.
Now... sudo make me a sandwich.
ratiocinativeroot.blogspot.com


Reply With Quote