统计本机内存情况和使用状况的脚本
简介:
#fetch and process memory information
[ -f /proc/meminfo ] && { #First judge whether the file exists
#-e是模式的意思,常用来保护以破折号开头的模式。
-
- [ -f /proc/meminfo ] && {
-
-
-
-
- Buffers=`grep -we 'Buffers' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
- Cached=`grep -we 'Cached' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
- MemFree=`grep -ie 'MemFree' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
- MemTotal=`grep -ie 'MemTotal' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
- SwapCached=`grep -ie 'SwapCached' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
- SwapFree=`grep -ie 'SwapFree' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
- SwapTotal=`grep -ie 'SwapTotal' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
- }
-
- MEMUSED="$(( ( ( ( $MemTotal - $MemFree ) - $Cached ) - $Buffers ) / 1024 ))"
- MEMTOTAL="$(( $MemTotal / 1024))"
- MEMFREE="$(( $MEMTOTAL - $MEMUSED ))"
- MEMPER="$(( ( $MEMUSED * 100 ) / $MEMTOTAL ))"
- [ "$SwapTotal" -gt "1" ] && {
- SWAPUSED="$(( ( ( $SwapTotal - $SwapFree ) - $SwapCached ) / 1024 ))"
- SWAPTOTAL="$(( $SwapTotal / 1024))"
- SWAPFREE="$(( $SWAPTOTAL - $SWAPUSED ))"
- SWAPPER="$(( ( $SWAPUSED * 100 ) / $SWAPTOTAL ))"
- } || {
- SWAPUSED="0"
- SWAPTOTAL="0"
- SWAPPER="0"
- }
-
-
- /bin/echo
- /bin/echo "Memory"
- /bin/echo "Used: $MEMUSED MB"
- /bin/echo "Free: $MEMFREE MB"
- /bin/echo "Total: $MEMTOTAL MB"
- /bin/echo
- /bin/echo "Swap"
- /bin/echo "Used: $SWAPUSED MB"
- /bin/echo "Free: $SWAPFREE MB"
- /bin/echo "Total: $SWAPTOTAL MB"
- /bin/echo