Hi guys,
I need a little help in scripting.
Code:
[root@base ~]# free -m
total used free shared buffers cached
Mem: 7766 6181 1585 0 200 1270
-/+ buffers/cache: 4710 3056
Swap: 5999 67 5932
I want this output in every 1 min repeatedly. I want to redirect value "3056" into a file.
Therefore, if I run the following command:
# free -m | grep buffers | tail -n 1 | awk '{print $4}' > test1
which is successful.
but when I run the command using "-s" option, it won't work.
# free -m -s 2 | grep buffers | tail -n 1 | awk '{print $4}' > test1
Can anybody tell me:
1. Why it is not working if I use '-s' switch ?
2. If it is not possible to use '-s' switch here, then is there any other way to run this command in every 2 seconds and get the require result into a file?
(If possible, I would prefer one liner script/command)
Thanks.