shell ÅжÏCPUÊÇ·ñ·±Ã¦£¡

×÷Õß: ËÕÎÄÁú 2012-07-23 16:32:27
[font=¿¬Ìå_GB2312]×î½üдһ¸öshell ³ÌÐò£¬ÆäÖÐÓÐÒ»¸öÒªÇ󣬾ÍÊÇÒªÖ§³Öϵͳ·±Ã¦¼ì²â¡£Èô棬ÔòÍ£Ö¹£¬ÈôÏУ¬ÔòÔËÐС£
˵ʵ»°£¬ÕâÖÖËã·¨¿Ï¶¨±È½Ï¶à£¬ÒÔÏÂÊÇÎÒ¸öÈ˵ÄÒ»¸öСËã·¨¡£Ìù³öÀ´ºÍ´ó¼Ò·ÖÏí¡£
ÎÒ¾õµÃͦ²»ÂúÒâ¡£Ìù³öÀ´µÄÄ¿µÄ¾ø²»ÊÇìÅÒ«£¬Õâ²»ÊÇìÅÒ«µÄµØ·½£¬Ò²²»ÊÇìÅÒ«µÄ×ʱ¾£¬¶øÊÇÏ£ÍûºÍ´ó¼ÒÓÐËù½»Á÷£¬Ï£Íû¿´µ½¸üºÃµÄËã·¨¡£ÎÒ¼áÐÅÓиüºÃµÄËã·¨³öÏÖ¡£Íû´ó¼Ò¶àÌáÒâ¼ûºÍ½¨Ò飡
[/font]
function 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;
}

Ïà¹Ø×ÊѶ