3

I have a long running operation that affects some state. That state is shown by running a certain command, say showst.

I want to see have a log of all the possible outputs showst will display during that long running operation.

For a short operation I would use

watch -n0.1 showst

And would just stare at the terminal looking at what is going on. But if the operation runs for an hour that is not very practical. I want to have a log that would tell me that at a specific time showst output changed to this. And then it changed to that.

Is there a command that can help me?


Edit to add a bit of clarification.

Here is a specific example of what I would like to see. Let's say that the operation runs for an hour. showst outputs A for the first half an hour, then B for 10 minutes, then switches to A again.

I want to see a log similar to this:

2016-08-19 12:00: A
2016-08-19 12:30: B
2016-08-19 12:40: A

It would be great if A and B could be multiline as well.

It is kind of like what watch --differences can do on a terminal, if you are sitting and watching, but I want that in a log.

1 Answers1

0

I don't know about a dedicated command, but I would have written something like that:

(while true; do sleep 0.1; showst; done) | uniq

Note: sleep implementations on Linux usually supports such floating arguments, but if you need a portable solution then you should use an integer argument there which limit the pooling to one second tick, or no sleep at all which will use your cpu a lot.

See also man pages of sleep and uniq.

A. Loiseau
  • 1,268