aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAN-TW <lantw44@gmail.com>2012-01-11 23:48:28 +0800
committerLAN-TW <lantw44@gmail.com>2012-01-11 23:48:28 +0800
commitd6791512c735864cf421d853c766e789ded7ff12 (patch)
tree1595a5a919c3507501eb2b860d9e0f4d4c570b56
parent22cac80359f0f58a2ef2e4b55b0daeca1dc0e074 (diff)
downloadconfigfile-d6791512c735864cf421d853c766e789ded7ff12.tar
configfile-d6791512c735864cf421d853c766e789ded7ff12.tar.gz
configfile-d6791512c735864cf421d853c766e789ded7ff12.tar.bz2
configfile-d6791512c735864cf421d853c766e789ded7ff12.tar.lz
configfile-d6791512c735864cf421d853c766e789ded7ff12.tar.xz
configfile-d6791512c735864cf421d853c766e789ded7ff12.tar.zst
configfile-d6791512c735864cf421d853c766e789ded7ff12.zip
bash_include: 支援在 GNU/Linux 顯示記憶體與置換空間用量bash_include-20120111
-rw-r--r--bash_include20
1 files changed, 20 insertions, 0 deletions
diff --git a/bash_include b/bash_include
index dbb94a4..3d22743 100644
--- a/bash_include
+++ b/bash_include
@@ -765,6 +765,26 @@ function keep_sudo_credential ()
done
}
+function get_memory_info ()
+{
+ if [ "`uname`" = "Linux" ]
+ then
+ local meminfoline="`free -m | \grep -i mem`"
+ local memtotal="`echo "$meminfoline" | awk '{print $2}'`"
+ local memused="`echo "$meminfoline" | awk '{print $3}'`"
+ local membuf="`echo "$meminfoline" | awk '{print $6}'`"
+ local memcache="`echo "$meminfoline" | awk '{print $7}'`"
+ local memprog=$(($memused-$membuf-$memcache))
+ echo "Memory: $memused / $memtotal MB (`printf %2d $(($memused*100/$memtotal))`%)"
+ echo "Detail:"
+ echo " Used: `printf %5d $memprog` MB (`printf %2d $(($memprog*100/$memtotal))`%)"
+ echo " Buffers: `printf %5d $membuf` MB (`printf %2d $(($membuf*100/$memtotal))`%)"
+ echo " Cached: `printf %5d $memcache` MB (`printf %2d $(($memcache*100/$memtotal))`%)"
+ else
+ echo "Current operating system is not Linux."
+ fi
+}
+
# Doing something
umask 0022