24小时热门版块排行榜    

查看: 490  |  回复: 0

wuy069

铁杆木虫 (正式写手)

[求助] 请教:用Shell, awk, perl等语言实现监视SGE集群节点和任务

http://muchong.com/bbs/viewthread.php?tid=5282178&fpage=1有100金币在这个帖子中
请教:用Shell, awk, perl等语言实现监视SGE集群节点和任务
简单的bash shell和awk语言会点,但弄个复杂的脚本,功底还是不够

[wuy@cluster test]$ qhost -j
HOSTNAME                ARCH         NCPU  LOAD  MEMTOT  MEMUSE  SWAPTO  SWAPUS
-------------------------------------------------------------------------------
global                  -               -     -       -       -       -       -
compute-0-0             lx26-amd64      4  2.97    3.9G    3.5G    4.0G    2.9G
   job-ID  prior   name       user         state submit/start at     queue      master ja-task-ID
   ----------------------------------------------------------------------------------------------
         6 0.50500 test1.sh   wuy          r     12/09/2012 14:47:26 all.q@comp MASTER        
         7 0.60500 test4.sh   wuy          r     12/09/2012 14:47:26 all.q@comp MASTER        
                                                                     all.q@comp SLAVE         
                                                                     all.q@comp SLAVE         
compute-0-1             lx26-amd64      4  3.56    3.9G    3.8G    4.0G    3.1G
   job-ID  prior   name       user         state submit/start at     queue      master ja-task-ID
   ----------------------------------------------------------------------------------------------
         8 0.60500 test2.sh   tester       r     12/09/2012 14:48:52 all.q@comp MASTER        
                                                                     all.q@comp SLAVE         
                                                                     all.q@comp SLAVE
         9 0.60500 test3.sh   tester       r     12/09/2012 14:48:52 all.q@comp MASTER        
                                                                     all.q@comp SLAVE         
                                                                     all.q@comp SLAVE
在compute-0-0节点上有两个任务6和7,所用的cpu分别为1和2;在compute-0-1节点上有两个任务8和9,所用的cpu分别为2和2.
使用Shell, awk, perl等语言获得的命令脚本打印输出下面所示:
------------------------------------------------------------------------------------------------
  node          state   load    ncpu   mem   memuse   swapto  swapus  tasks  jobids/users     
------------------------------------------------------------------------------------------------
compute-0-0    free    2.97     4    3.9G   3.5G     4.0G    2.9G      3     6/wuy 7/wuy
compute-0-1    busy    3.56     4    3.9G   3.8G     4.0G    3.1G      4     8/tester 9/tester

其中,当node的LOAD为“-”时,相应node的state为down.

下面是根据qstat命令编写脚本监视任务的申请时间和逝去时间
[wuy@cluster test]$ qstat -u '*'
job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID
-----------------------------------------------------------------------------------------------------------------
      6 0.50500 test1.sh   wuy          r     12/09/2012 14:47:26 all.q@compute-0-0.local            1        
      7 0.60500 test4.sh   wuy          r     12/09/2012 14:47:26 all.q@compute-0-0.local            2  
      8 0.60500 test2.sh   tester       r     12/09/2012 14:48:52 all.q@compute-0-1.local            2        
      9 0.60500 test3.sh   tester       r     12/09/2012 14:48:52 all.q@compute-0-1.local            2
[wuy@cluster test]$ qstat -j 6 |grep h_rt
hard resource_list:         h_rt=3600
得到的申请时间(reqtime)为3600s,改为小时制:1:00:00
逝去的时间(elaptime)为现在的时间`date`减去任务开始的时间

使用Shell, awk, perl等语言获得的命令脚本打印输出下面所示
job-ID   name       user         state submit/start at     queue                      slots   reqtime      elaptime
--------------------------------------------------------------------------------------------------------------------
      6  test1.sh   wuy          r     12/09/2012 14:47:26 all.q@compute-0-0.local      1      1:00:00     00:50:00
      7  test4.sh   wuy          r     12/09/2012 14:47:26 all.q@compute-0-0.local      2      2:00:00     00:50:00
      8  test2.sh   tester       r     12/09/2012 14:48:52 all.q@compute-0-1.local      2      5:00:00     00:48:34
      9  test3.sh   tester       r     12/09/2012 14:48:52 all.q@compute-0-1.local      2     12:00:00     00:48:34
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 wuy069 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 工科材料085601 279求调剂 +6 困于星晨 2026-03-17 6/300 2026-03-18 10:21 by kkcoco25
[考研] 278求调剂 +5 烟火先于春 2026-03-17 5/250 2026-03-18 08:43 by 星空星月
[考研] 326求调剂 +5 上岸的小葡 2026-03-15 6/300 2026-03-17 17:26 by ruiyingmiao
[考研] 308求调剂 +4 是Lupa啊 2026-03-16 4/200 2026-03-17 17:12 by ruiyingmiao
[考研] 290求调剂 +6 孔志浩 2026-03-12 11/550 2026-03-17 14:41 by 周舟舟77
[考研] 一志愿,福州大学材料专硕339分求调剂 +3 木子momo青争 2026-03-15 3/150 2026-03-17 07:52 by laoshidan
[考研] 333求调剂 +3 文思客 2026-03-16 7/350 2026-03-16 18:21 by 文思客
[考研] 一志愿985,本科211,0817化学工程与技术319求调剂 +5 Liwangman 2026-03-15 5/250 2026-03-16 17:10 by 我的船我的海
[考研] 0703化学调剂 +6 妮妮ninicgb 2026-03-15 9/450 2026-03-16 16:40 by houyaoxu
[考研] 070300化学学硕求调剂 +6 太想进步了0608 2026-03-16 6/300 2026-03-16 16:13 by kykm678
[考研] 085601材料工程315分求调剂 +3 yang_0104 2026-03-15 3/150 2026-03-15 10:58 by peike
[考研] 255求调剂 +3 李嘉慧, 2026-03-12 4/200 2026-03-14 16:58 by 有只狸奴
[考研] 材料080500调剂求收留 +3 一颗meteor 2026-03-13 3/150 2026-03-14 10:54 by peike
[考研] 招收0805(材料)调剂 +3 18595523086 2026-03-13 3/150 2026-03-14 00:33 by 123%、
[考研] 求b区学校调剂 +3 周56 2026-03-11 3/150 2026-03-13 16:20 by JourneyLucky
[考研] 材料专硕350 求调剂 +4 王金科 2026-03-12 4/200 2026-03-13 16:02 by ruiyingmiao
[考研] 一志愿211化学学硕310分求调剂 +8 努力奋斗112 2026-03-12 9/450 2026-03-13 15:41 by JourneyLucky
[考研] 314求调剂 +7 无懈可击的巨人 2026-03-12 7/350 2026-03-13 15:40 by JourneyLucky
[考研] 328化工专硕求调剂 +4 。,。,。,。i 2026-03-12 4/200 2026-03-13 14:44 by JourneyLucky
[考研] 0817化学工程与技术考研312分调剂 +3 T123 tt 2026-03-12 3/150 2026-03-13 10:49 by houyaoxu
信息提示
请填处理意见