1)cpu_monitor
1@@@@show of shell
@@@the shell display the color of apply.
@@@there are many skill in this shell.
[root@station78 color]# cat cpu_color.sh
#!/bin/sh
#RHEL6.2_x86_64
#declare: may be do some change, if you want to run in different platform.
#set -x
###claim all the color and font type. not apply for all shell.
def_colors(){
# Attributes
normal='\033[0m'; bold='\033[1m'; dim='\033[2m'; under='\033[4m'
italic='\033[3m'; noitalic='\033[23m'; blink='\033[5m';
reverse='\033[7m'; conceal='\033[8m' nobold='\033[22m';
nounder='\033[24m'; noblink='\033[25m'
# Foreground
black='\033[30m'; red='\033[31m'; green='\033[32m'; yellow='\033[33m'
blue='\033[34m'; magenta='\033[35m'; cyan='\033[36m'; white='\033[37m'
# Background
bblack='\033[40m'; bred='\033[41m'
bgreen='\033[42m'; byellow='\033[43m'
bblue='\033[44m'; bmagenta='\033[45m'
bcyan='\033[46m'; bwhite='\033[47m'
}
def_colors

####check the intel or amd of your machine.
####display the processor,nisdomain,cache,vendor
clear
hostname=`cat /proc/sys/kernel/hostname`
echo
echo -e "System Report for $white$hostname$normal on `date`"
echo
processor=`grep 'model name' /proc/cpuinfo | cut -d: -f2 | cut -c2-`
nisdomain=`cat /proc/sys/kernel/domainname`
cache=`grep 'cache size' /proc/cpuinfo | awk '{print $4,$5}'`
bogomips=`grep 'bogomips' /proc/cpuinfo | awk '{print $3}'`
vendor=`grep 'vendor_id' /proc/cpuinfo`
echo -e "Hostname: $white$hostname$normal NIS Domain: $white$nisdomain$normal"
if [ "`echo $vendor | grep -i intel`" ];then
   cpu_color=$blue
elif [ "`echo $vendor | grep -i amd`" ];then
   cpu_color=$green
fi
echo -e " Processor: "
echo -e "$cpu_color$processor$normal"
echo -e " Running at:"
echo -e "$white$bogomips$normal "
echo -e " bogomips with"
echo -e "$white$cache$normal cache"
echo " "


####check the usage of your memory.
####less then 80 => green
####between 80 and 90 => yellow
####bigger then 90 => red
ostype=`cat /proc/sys/kernel/ostype`
osrelease=`cat /proc/sys/kernel/osrelease`
rev=`cat /proc/sys/kernel/version | awk '{print $1}'`
da_date=`cat /proc/sys/kernel/version | cut -c 3-`
upsec=`awk '{print $1}' /proc/uptime`
uptime=`echo "scale=2;$upsec/86400" | bc`
echo -e "OS Type: $white$ostype$normal Kernel:\
$white$osrelease$normal"
echo -e "Kernel Compile $white$rev$normal on\
$white$da_date$normal"
echo -e "Uptime: $magenta$uptime$normal days"
set `grep MemTotal /proc/meminfo`
tot_mem=$2 ; tot_mem_unit=$3
set `grep MemFree /proc/meminfo`
free_mem=$2 ; fre_mem_unit=$3
perc_mem_used=$((100-(100*free_mem/tot_mem)))
set `grep SwapTotal /proc/meminfo`
tot_swap=$2 ; tot_swap_unit=$3
set `grep SwapFree /proc/meminfo`
free_swap=$2 ; fre_swap_unit=$3
perc_swap_used=$((100-(100*free_swap/tot_swap)))
if [ $perc_mem_used -lt 80 ]
then
mem_color=$green
elif [ $perc_mem_used -ge 80 -a $perc_mem_used -lt 90 ]
then
mem_color=$yellow
else
mem_color=$red
fi
if [ $perc_swap_used -lt 80 ]
then
swap_color=$green
elif [ $perc_swap_used -ge 80 -a $perc_swap_used -lt 90 ]
then
swap_color=$yellow
else
swap_color=$red
fi
echo -e "Memory: $white$tot_mem$normal $tot_mem_unit Free: $white$free_mem$normal \
$fre_mem_unit %Used: $mem_color$perc_mem_used$normal"
echo -e "Swap: $white$tot_swap$normal $tot_swap_unit Free: $white$free_swap$normal \
$fre_swap_unit %Used: $swap_color$perc_swap_used$normal"
echo


####evaluate the load
####the output of set `cat /proc/loadavg` was treated as input $1 $2 $3
set `cat /proc/loadavg`
one_min=$1
five_min=$2
fifteen_min=$3
echo -n "Load Average:"  #@@@do not change line.
for ave in $one_min $five_min $fifteen_min
do
echo $ave > /tmp/ave.tmp
int_ave=`cat /tmp/ave.tmp | cut -d. -f1` #@@@you could not echo $ave directly here(RHEL6.2_x86_64).
if [ $int_ave -lt 1 ]
then
echo -en " $green$ave$normal"
elif [ $int_ave -ge 1 -a $int_ave -lt 5 ]
then
echo -en " $yellow$ave$normal"
else
echo -en " $red$ave$normal"
fi
done
echo

####all the process have it's status => /proc/[id_number]/stats
####calculate the total number of processes with four status.
running=0; sleeping=0 stopped=0; zombie=0
for pid in /proc/[1-9]*
do
procs=$((procs+1))
stat=`awk '{print $3}' $pid/stat`
case $stat in
R) running=$((running+1));;
S) sleeping=$((sleeping+1));;
T) stopped=$((stopped+1));;
Z) zombie=$((zombie+1));;
esac
done
echo -n "Process Count: "
echo -e "$white$procs$normal total $white$running$normal running\
$white$sleeping$normal sleeping $white$stopped$normal stopped\
$white$zombie$normal zombie"
echo






2@@@@test the shell
[root@station78 color]# ./cpu_color.sh

System Report for station78.example.com on Sat Jul 14 16:18:55 CST 2012

Hostname: station78.example.com NIS Domain: (none)
 Processor:
Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
 Running at:
5582.21
5582.23
5582.28
5589.15
 bogomips with
4096 KB
4096 KB
4096 KB
4096 KB cache
 
OS Type: Linux Kernel:2.6.32-220.el6.x86_64
Kernel Compile #1 on SMP Wed Nov 9 08:03:13 EST 2011
Uptime: .06 days
Memory: 7943348 kB Free: 3221708 kB %Used: 60
Swap: 1048568 kB Free: 1048568 kB %Used: 0

Load Average: 3.25 1.53 0.63
Process Count: 335 total 0 running333 sleeping 0 stopped0 zombie