24小时热门版块排行榜    

Znn3bq.jpeg
北京石油化工学院2026年研究生招生接收调剂公告
查看: 498  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 273求调剂 +37 麦小叮当 2026-04-06 44/2200 2026-04-08 08:51 by edward198412
[考研] 环境专硕调剂 +13 会说话的肘子 2026-04-06 13/650 2026-04-08 07:00 by lijunpoly
[考研] 生物医药调剂|SCI中科院三区一作+多项科研成果 +8 likangxing 2026-04-07 11/550 2026-04-08 00:02 by lys0704
[考研] 278求调剂 +13 范婷娜 2026-04-07 14/700 2026-04-07 22:42 by 来看流星雨10
[考研] 316求调剂 +7 yyx想调剂 2026-04-05 7/350 2026-04-07 14:31 by shdgaomin
[考研] 一志愿郑州大学085600求调剂 +20 吃的不少 2026-04-05 23/1150 2026-04-07 10:05 by 猪会飞
[考研] 336求调剂,一志愿中科大 +7 墨彧 yuyu 2026-04-06 7/350 2026-04-07 08:58 by Jaylen.
[考研] 一志愿国科大信工所,英二数二408总分293分求调剂 +3 ilcyuan 2026-04-02 4/200 2026-04-06 16:35 by likeihood
[考研] 求调剂 +4 wos666 2026-04-03 5/250 2026-04-06 15:22 by wos666
[考研] 一志愿安徽某211 0703化学总分339求调剂 +7 晚风不晚 2026-04-04 7/350 2026-04-06 14:06 by houyaoxu
[考研] 材料专硕283求调剂 +17 试试看呗 2026-04-04 18/900 2026-04-06 09:24 by 286640313
[考研] 材料求调剂 +10 呢呢妮妮 2026-04-01 10/500 2026-04-04 23:12 by 无际的草原
[考研] 材料383求调剂 +5 郭阳阳阳成 2026-04-04 5/250 2026-04-04 19:06 by dongzh2009
[考研] 求调剂 +3 ffyyu 2026-04-02 3/150 2026-04-04 19:03 by 蓝云思雨
[考研] 319求调剂 +4 星星不眨眼喽 2026-04-03 4/200 2026-04-04 16:25 by 中飞院空管学院
[考研] 一志愿北京科技大学材料工程085601,求调剂 +17 cdyw 2026-04-02 18/900 2026-04-04 11:14 by w_xuqing
[考研] 求调剂机会 +5 意染ivy 2026-04-03 5/250 2026-04-03 15:13 by qoooooo614
[考研] 机械专硕297 +3 Afksy 2026-04-03 3/150 2026-04-03 14:24 by 1753564080
[考研] 071000生物学调剂 +8 知昭蔓 2026-04-02 8/400 2026-04-03 10:36 by macy2011
[考研] 调剂 +7 祉岷. 2026-04-02 7/350 2026-04-03 09:11 by 花呗还欠600
信息提示
请填处理意见