I need to write a script to display VMSTAT every 5 seconds and I just need the memory columns - swap free re and just the numbers and the headers arent required.
For example
bash-3.00$ vmstat 5| awk '{print $4" "$5" "$6}'
disk faults cpu ------ This header isnt required
swap free re ------ This header isnt required
36889520 7061456 11
Also I need to append the output of this comman in a file after every 5 seconds
Beware that the first line of statistics from vmstat are garbage.
Therefor anchal_khare post will not produce valid results.
Also beware that "vmstat 5" will not stop until it is interrupted or killed.
To get meaningful statistics from vmstat it must be run with at least two iterations:
vmstat 5 2
Then take the statistics from the last line output.
A 5-second snapshot of a unix system would be biased by vmstat itself.
In practice you get a more meaningful statistics from say: