nighthoodie

free

Apr 27th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.40 KB | None | 0 0
  1. #!/bin/bash
  2. # return free memory in MB
  3.  
  4. #method 1: short but slow
  5. ##########################
  6. #top="/usr/bin/top"
  7. #grep="/usr/bin/grep"
  8. #cut="/usr/bin/cut"
  9. #top -l 1 | grep ^PhysMem |cut -c62-66
  10.  
  11. #method 2:
  12. ##########################
  13. vm_stat="/usr/bin/vm_stat"
  14. awk="/usr/bin/awk"
  15. free="$(( $(vm_stat | awk '/free/ {gsub(/\./, "", $3); print $3}') * 4096 / 1048576)) MiB free RAM"
  16. echo="/bin/echo"
  17. echo $free
  18.  
  19.  
  20. exit
Add Comment
Please, Sign In to add comment