#!/usr/bin/awk -f function getvar(label) { while (getline < meminfo && $1 != label":"); return $2 } BEGIN { meminfo="/proc/meminfo" # Make sure these are in order of the output of /proc/meminfo memtotal = getvar("MemTotal") memfree = getvar("MemFree") buffers = getvar("Buffers") cached = getvar("Cached") shmem = getvar("Shmem") sreclaimable = getvar("SReclaimable") # Htop calculations totalused = memtotal - memfree totalcached = cached + sreclaimable - shmem noncachenonbuf = totalused - (buffers + totalcached) # Print % of memory used print int((noncachenonbuf * 100) / memtotal)"%" } #BEGIN { # cmd="free -b" # cmd | getline # cmd | getline # print int($3*100/$2)"%" #} ##awk '{ if(!total){ total = $2 } else if(!free){ free = $2 } else{ exit } } END{ print int(((total-free)*100)/total)"%" }' /proc/meminfo