#!/bin/bash LABEL=${LABEL:"+"} TYPE="${TYPE:-mem}" awk -v type=$TYPE ' /^MemTotal:/ { mem_total=$2 } /^MemFree:/ { mem_free=$2 } /^Buffers:/ { mem_free+=$2 } /^Cached:/ { mem_free+=$2 } END { free=mem_free/1024/1024 used=(mem_total-mem_free)/1024/1024 total=mem_total/1024/1024 pct=0 if (total > 0) { pct=used/total*100 } # Full text. # printf("%s %.1fG/%.1fG (%.f%%)\n", LABEL, used, total, pct) printf("%s %.1fG\n", LABEL, used) # Short text. printf("%s %.f%%\n", LABEL, pct) # Color. if (pct > 90) { print("#FF0000") } else if (pct > 80) { print("#FFAE00") } else if (pct > 70) { print("#FFF600") } } ' /proc/meminfo