免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2059 | 回复: 7

高手帮忙解释此脚本 [复制链接]

论坛徽章:
0
发表于 2012-02-01 19:04 |显示全部楼层
本帖最后由 princeduan 于 2012-02-08 12:46 编辑

  1. #! /opt/perl/bin/perl

  2. #
  3. #xp4 ps wrapper
  4. #
  5. $ENV{UNIX95}=qq(XPG4);

  6. #
  7. #-o arg definition
  8. #
  9. #ps -el + VSZ
  10. $0_arg = qq(flags,state,user,pid,ppid,cpu,intpri,nice,addr,sz,vsz,wchan,stime,tty,time,args);
  11. #ps -ef + sz,vsz
  12. $o_arg = qq(user,pid,ppid,cpu,stime,tty,time,sz,vsz,args);

  13. #-C ag definition

  14. $C_arg = qq();

  15. $header = 1;
  16. $filter = qq(oracle|hul|jp1);

  17. $cmd = qq(ps -o $o_arg);

  18. if ($C_arg =~ /`$/) {
  19.     $cmd .= qq(-e);
  20. } else {
  21.      $cmd .= qq(-C $C_arg);
  22. }

  23. open(FH, "$cmd |") || die;
  24. while (<FH>) {
  25.     if ($header) {
  26.         print;
  27.         $header = 0;
  28.     } else {
  29.         if ($filter =~ /`$/) {
  30.             print;
  31.         } elsif (/$filter/) {
  32.             print;
  33.         }
  34.     }
  35. }
  36. close(FH);
  37. exit 0;
复制代码
谢谢!:wink:

论坛徽章:
0
发表于 2012-02-01 19:45 |显示全部楼层
楼主不如说说自己哪里不明白的、需要解释的地方。

脚本的主要功能是运行ps命令(unix系统上正在运行的进程列表),得出结果进行分析并显示出来。

论坛徽章:
0
发表于 2012-02-05 19:58 |显示全部楼层
感觉和一般的shell脚本不太一样,基本上看不懂。
能帮忙解释下2,6,8,9,11行的意思吗?
{:3_200:}

论坛徽章:
0
发表于 2012-02-05 21:26 |显示全部楼层
princeduan 发表于 2012-02-05 19:58
感觉和一般的shell脚本不太一样,基本上看不懂。
能帮忙解释下2,6,8,9,11行的意思吗?


2,6,8,9,11,不知道你是不是想让解释qq的意思?
qq就是“”,双引号。

论坛徽章:
46
15-16赛季CBA联赛之四川
日期:2018-03-27 11:59:132015年亚洲杯之沙特阿拉伯
日期:2015-04-11 17:31:45天蝎座
日期:2015-03-25 16:56:49双鱼座
日期:2015-03-25 16:56:30摩羯座
日期:2015-03-25 16:56:09巳蛇
日期:2015-03-25 16:55:30卯兔
日期:2015-03-25 16:54:29子鼠
日期:2015-03-25 16:53:59申猴
日期:2015-03-25 16:53:29寅虎
日期:2015-03-25 16:52:29羊年新春福章
日期:2015-03-25 16:51:212015亚冠之布里斯班狮吼
日期:2015-07-13 10:44:56
发表于 2012-02-05 21:29 |显示全部楼层
最专业的解释
q/STRING/
'STRING'


A single-quoted, literal string. A backslash represents a backslash unless followed by the delimiter or another backslash, in which case the delimiter or backslash is interpolated.
  1.     $foo = q!I said, "You said, 'She said it.'"!;
  2.     $bar = q('This is it.');
  3.     $baz = '\n'; # a two-character string
复制代码
qq/STRING/
"STRING"


A double-quoted, interpolated string.
  1.     $_ .= qq
  2.     (*** The previous line contains the naughty word "$1".\n)
  3.     if /\b(tcl|java|python)\b/i; # :-)
  4.     $baz = "\n"; # a one-character string
复制代码

论坛徽章:
0
发表于 2012-02-05 21:31 |显示全部楼层
perl, 看不懂

论坛徽章:
0
发表于 2012-02-05 21:47 |显示全部楼层
能不能帮忙把每行具体的意思说下?

论坛徽章:
0
发表于 2012-02-06 17:52 |显示全部楼层
此脚本进行了更新。哪位高手能帮忙解释下?
每行简单一句话就可以。{:3_200:}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP