Skip to content

Instantly share code, notes, and snippets.

@jgoodall
Created November 12, 2012 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgoodall/4061026 to your computer and use it in GitHub Desktop.
Save jgoodall/4061026 to your computer and use it in GitHub Desktop.
shell script to print memory usage to the screen (geektool)
#!/bin/sh
# useful for [geektool](http://projects.tynsoe.org/en/geektool/)
/usr/bin/vm_stat | sed 's/\.//' | awk '
/free/ {FREE_BLOCKS = $3}
/inactive/ {INACTIVE_BLOCKS = $3}
/speculative/ {SPECULATIVE_BLOCKS = $3}
/wired/ {WIRED_BLOCKS = $4}
END {
TOTAL = 16384
FREE = ((FREE_BLOCKS + SPECULATIVE_BLOCKS) * 4096) / 1048576
INACTIVE = (INACTIVE_BLOCKS * 4096) / 1048576
TOTAL_FREE = FREE + INACTIVE
WIRED = (WIRED_BLOCKS * 4096) / 1048576
ACTIVE = TOTAL - (TOTAL_FREE + WIRED)
TOTAL_USED = INACTIVE + WIRED + ACTIVE
printf "Free: %d\n", FREE
printf "Inactive: %d\n", INACTIVE
printf "Total Free: %d\n", TOTAL_FREE
printf "Wired: %d\n", WIRED
printf "Active: %d\n", ACTIVE
printf "Total Used: %d\n", TOTAL_USED
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment