I am trying to write a command that pipes the continuous output of a free command (run every second) to an awk command that parses a specific value (available free memory) and outputs this to a file with a timestamp. Here are my current attempts at the command:
free -mto -s 1 | awk '/Mem/ { print strftime("%r") "," $4 }' >>memOut
And alternatively, after a bit of Googling
free -mto -s 1 | awk '/Mem/ { print strftime("%r") "," $4 >>"memOut"}'
Each run produces empty files. Any suggestions or possibly different methods?
Best Answer
You have to flush the buffer to see something in
memOut
during the execution:Here's an alternative version: