Just use a loop:
while : ; do free -m | grep buffers; sleep 1; done
The colon is equivalent to true
.
Redirect to a file called time
if you like:
while : ; do free -m | grep buffers >> time; sleep 1; done
Question
I am writing a test script and need to gather "free -m" output at some interval at background. However, watch cmd
sends control sequences to delete old output, thinking it is in a terminal. But I don't want that, I want the values throught the process. Is this possible?
In short; I run
watch -n 1 "free -m | grep buffers/cache" > time
And I expect time to have multiple lines of:
-/+ buffers/cache: 2212 5730
-/+ buffers/cache: 2219 5730
-/+ buffers/cache: 2217 5730
However it only contains:
0u May 8 20:39:19 2014
-/+ buffers/cache: 2212 5730
Solution
Just use a loop:
while : ; do free -m | grep buffers; sleep 1; done
The colon is equivalent to true
.
Redirect to a file called time
if you like:
while : ; do free -m | grep buffers >> time; sleep 1; done