Learn More Learn More - 11 months ago 38
Linux Question

Free command linux

I am trying to do following:

Get output of free -mo , take the 2nd line and log it to a file every 30 seconds.

When I run

$free -mo -s 30


It runs and displays output every 30 seconds.

But when I run

$ free -mo -s 30 | head -2 | tail -1


It runs only once. I am not able to figure out what is wrong.

free Manual says free -s 30 run the command every 30 seconds.

Answer Source

head -2 returns only the first 2 lines of output then quits. tail -1 returns the last line, then quits. When any program quits in a pipeline, it kills the entire pipeline, so free is stopped when head and tail finish.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download