The script is a little old but still works. However, on boxes with very large amounts of RAM (100G+), top doesn't give an answer in K anymore and the script breaks.
I took out the if statement in the main loop that grabs the memory and replaced it with: