usedram 710 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. mem_info=$(</proc/meminfo)
  3. mem_info=$(echo $(echo $(mem_info=${mem_info// /}; echo ${mem_info//kB/})))
  4. for m in $mem_info; do
  5. case ${m//:*} in
  6. "MemTotal") usedmem=$((usedmem+=${m//*:})); totalmem=${m//*:} ;;
  7. "ShMem") usedmem=$((usedmem+=${m//*:})) ;;
  8. "MemFree"|"Buffers"|"Cached"|"SReclaimable") usedmem=$((usedmem-=${m//*:})) ;;
  9. esac
  10. done
  11. usedmem=$((usedmem / 1024))
  12. totalmem=$((totalmem / 1024))
  13. mem="${usedmem}MB / ${totalmem}MB"
  14. ## Complete summary
  15. if [[ $1 = "-fi" ]]; then
  16. echo " $mem"
  17. elif [[ $1 = "-f" ]]; then
  18. echo "$mem"
  19. ## Only used RAM
  20. elif [[ $1 = "-i" ]]; then
  21. echo " $usedmem MB"
  22. else
  23. echo "$usedmem MB"
  24. fi