#!/bin/sh
drawChart()
{
COUNT=0
MAX=30
CHARTWIDTH=`expr $MAX - 2`
CHARTUSED=`expr $2 '*' $MAX / $1`
CHARTFREE=`expr $CHARTWIDTH - $CHARTUSED`
echo -n "["
while [ $COUNT -lt $MAX ] ;
do
if [ $COUNT -lt $CHARTUSED ]; then
echo -n "#"
else
echo -n "."
fi
COUNT=`expr $COUNT + 1`
done
echo "] ($3% occupied)"
}
RAM=`free -m | grep Mem`
SWAP=`free -m | grep Swap`
RAMTOTAL=`echo $RAM | awk '{ print $2 }'`
RAMUSED=`echo $RAM | awk '{ print $3 }'`
SWAPTOTAL=`echo $SWAP | awk '{ print $2 }'`
SWAPUSED=`echo $SWAP | awk '{ print $3 }'`
RAMPERCENT=`expr 100 '*' $RAMUSED '/' $RAMTOTAL`
SWAPPERCENT=`expr 100 '*' $SWAPUSED '/' $SWAPTOTAL`
echo "RAM (total: $RAMTOTAL MB; used: $RAMUSED MB)"
drawChart $RAMTOTAL $RAMUSED $RAMPERCENT
echo
echo "SWAP (total: $SWAPTOTAL MB; used: $SWAPUSED MB)"
drawChart $SWAPTOTAL $SWAPUSED $SWAPPERCENT