Skip to content

Instantly share code, notes, and snippets.

@frjufvjn
Last active March 25, 2021 03:28
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 frjufvjn/b29f748f2652456e22c148fda2d85b1e to your computer and use it in GitHub Desktop.
Save frjufvjn/b29f748f2652456e22c148fda2d85b1e to your computer and use it in GitHub Desktop.
free -m | \
awk '
{
if (NR==1) {
if (/cached$/) {
vesion=0
} else {
version=1
}
} else {
if (/^Mem/) {
if (version==0) {
usage1 = ($3 - $6 - $7) / $2 * 100
print "memory usage: " usage1
} else {
usage2 = ($2 - $7) / $2 * 100
print "memory usage: " usage2
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment