#!/bin/bash
#filename chk_cpu.sh
#edit by www.jbxue.com
busy()
{
touch cpu.txt;
echo -e "\033[31m \n Detecting the %idle of CPU ... \033[0m ";
export temp=1;
sar -u 1 3 | awk '{print$9}' | tail -n 4 >>cpu.txt ;
tail -n 4 cpu.txt | cut -d "." -f 1 | while read var;
do
#echo $var;
if [[ $var -ge 20 ]];then
delete; ### Run into delete function
exit;
fi
temp=$[ $temp + 1 ];
if [ $temp -eq 4 ];then
echo -e "\n \033[37;5m So sorry, System is busy now ! \n\033[0m ";
fi
done;
rm -rf cpu.txt;
}
#use busy()
busy()
#!/bin/sh
#filename chk_cpu_memory.sh
#edit by www.jbxue.com
clear
while ((1>0))
do
NET=$(netstat -anp | grep 1000 | grep EST | wc -l)
PRC=$(ps aux | grep thread1 | grep -v grep | grep -v SCREEN | awk '{ print " CPU: " $3 "%, MEM: " $4 "%, RSS: " $6/1024 "M, VSZ: " $5/1024 "M, PID: "
$2 ""}')
tput sc; echo -n -e "\b"; tput rc;
echo "SRV: thread1, NET: $NET, $PRC"
echo ""
NET=$(netstat -anp | grep 1011 | grep EST | wc -l)
PRC=$(ps aux | grep thread2 | grep -v grep | grep -v SCREEN | awk '{ print " CPU: " $3 "%, MEM: " $4 "%, RSS: " $6/1024 "M, VSZ: " $5/1024 "M, PID: "
$2 ""}')
tput sc; echo -n -e "\b"; tput rc;
echo "SRV: thread2, NET: $NET, $PRC"
echo ""
NET=$(netstat -anp | grep 1022 | grep EST | wc -l)
PRC=$(ps aux | grep thread3 | grep -v grep | grep -v SCREEN | awk '{ print " CPU: " $3 "%, MEM: " $4 "%, RSS: " $6/1024 "M, VSZ: " $5/1024 "M, PID: "
$2 ""}')
tput sc; echo -n -e "\b"; tput rc;
echo "SRV: thread3, NET: $NET, $PRC"
echo ""
NET=$(netstat -anp | grep 1033 | grep EST | wc -l)
PRC=$(ps aux | grep thread4 | grep -v grep | grep -v SCREEN | awk '{ print " CPU: " $3 "%, MEM: " $4 "%, RSS: " $6/1024 "M, VSZ: " $5/1024 "M, PID: "
$2 ""}')
tput sc; echo -n -e "\b"; tput rc;
echo "SRV: thread4, NET: $NET, $PRC"
echo ""
NET=$(netstat -anp | grep beam.smp | grep EST | grep 222.222.18.222:800 | wc -l)
PRC=$(ps aux | grep thread | grep -v grep | awk '{CPU += $3} {MEM += $4} {RSS += $6} {VSZ += $5} END {print "CPU: " CPU "%, MEM: " MEM "%, RSS: "
RSS/1024 "M, VSZ: " VSZ/1024 "M, " " "}' | awk 'END {print}')
tput sc; echo -n -e "\b"; tput rc;
echo "SRV: All, NET: $NET, $PRC"
echo ""
sleep 0.5
tput cup 0 0
done
#!/bin/bash
#filename get_cpu_info.sh
#edit by www.jbxue.com
cpu_p=`cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l`
cpu_c=`cat /proc/cpuinfo | grep "core id" | uniq | wc -l`
cpu_l=`cat /proc/cpuinfo | grep "processor" | wc -l`
c_p=`expr $cpu_c / $cpu_p`
l_p=`expr $cpu_l / $cpu_p`
t_c=`expr $cpu_l / $cpu_c`
echo "Physical CPU Count: $cpu_p"
echo "CPU Core Count : $cpu_c"
echo "Logical CPU Count: $cpu_l"
echo "$c_p cores per physical CPU"
echo "$l_p logical CPUs per physical CPU"
echo "$t_c threads per core"
if [ $c_p -eq 1 ]; then
echo "Your CPU is unicore"
else
echo "Your CPU is multicore"
fi
if [ $t_c -eq 1 ]; then
echo "Your CPU isn\'t of HT"
else
echo "Your CPU is of HT"
fi
echo "You have $cpu_p CPUs, each CPU has $c_p cores, each core has $t_c threads. In summary $cpu_c cores, $cpu_l threads."