rendered paste body#!/bin/sh
#
# GNU-GPL fully posix compliant and should work with all 2.[2-6].* kernels
#
# it just displays color-coded memory information. nothing fancy.
#
# define colors
normal='\033[0m'
boldred='\033[31m\033[1m'
boldgreen='\033[32m\033[1m'
boldyellow='\033[33m\033[1m'
#fetch and process memory information
[ -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))"
MEMPER="$(( ( $MEMUSED * 100 ) / $MEMTOTAL ))"
[ "$SwapTotal" -gt "1" ] && {
SWAPUSED="$(( ( ( $SwapTotal - $SwapFree ) - $SwapCached ) / 1024 ))"
SWAPTOTAL="$(( $SwapTotal / 1024))"
SWAPPER="$(( ( $SWAPUSED * 100 ) / $SWAPTOTAL ))"
} || {
SWAPUSED="0"
SWAPTOTAL="0"
SWAPPER="0"
}
# display the memory information in color-coded output
/bin/echo
/bin/echo -e "Memory:$boldred Used$normal $boldgreen Total$normal"
/bin/echo -e "$boldred $MEMUSED$normal $boldgreen $MEMTOTAL$normal"
/bin/echo -e "-----------------------"
/bin/echo -e "Percent used:$boldyellow ($MEMPER%)$normal"
/bin/echo
/bin/echo -e "Swap:$boldred Used$normal $boldgreen Total$normal"
/bin/echo -e "$boldred $SWAPUSED$nomral $boldgreen $SWAPTOTAL$normal"
/bin/echo -e "-----------------------"
/bin/echo -e "Percent used:$boldyellow ($SWAPPER%)$normal"
/bin/echo