每日一脚本系列

3279阅读 0评论2009-12-12 jiannma
分类:LINUX

最近在坛子里突然想搞个每日一脚本系列啊,作为自己每天的成果啊。。

呵呵 ~  大虾们不要见笑啊。。


偶是新手啊, 脚本中如果有什么修改的地方也希望大家多多提建议啊


好了, 废话不多说了,直接上脚本, 今天写的 脚本是用来显示CPU的使用情况:

我使用的是csh , bash的话可以自己修改下,就不详细说明了。。。

==========================================================
#!/bin/csh

#This program is used to check the CPU usage

echo "Checking the machine CPU usage ...\n"

set PSFLAGS = "-e -o user,pid,pcpu,comm"

ps $PSFLAGS |\
       sed -e 1d |\
         sort -br -k3,3 -k4,4|\
           uniq|\
             sed -n '1,3p'|\
               awk 'BEGIN{ \
                     print "username\tpid\tcpu\tcomm\n----------------------------------------"}\
                     {\
                         printf ("%-15s\t%s\t%s\t%s\n", $1, $2,$3,$4)}'


运行结果为:
Checking the machine CPU usage ...

username        pid     cpu     comm
----------------------------------------
jian.ma         9110    71.7    VirtualBox
root            2871    2.0     Xorg
jian.ma         3290    0.9     rdesktop



上一篇:技巧总结
下一篇:Perl for Win32 安装