source: trunk/examples/topjob @ 281

Last change on this file since 281 was 281, checked in by bas, 12 years ago

some svn properties

  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 2.4 KB
Line 
1#!/usr/bin/env python
2#
3# Author:
4#  Willem Vermin, SARA, April 2012
5#
6# SVN Info:
7#   $Id#
8#   $URL: trunk/examples/topjob $
9#
10# topjob, gojob jobnr [nodenr]
11#               jobnr: the number of the job
12#               nodenr: the rank of the node in the job
13# depending on the name with this script is called it performs the
14# following:
15
16# called as topjob:
17#       shows the output of top -u user on the node
18#       - one cycle of top
19#       - user: the user the job belongs to
20#
21# called as gojob:
22#       logs in to the node as the user who invokes this script
23#            (os.getenv('USER'))
24#
25from PBSQuery import PBSQuery
26import sys,os
27def uniq(seq, idfun=None): 
28  # http://www.peterbe.com/plog/uniqifiers-benchmark
29   # order preserving
30   if idfun is None:
31       def idfun(x): return x
32   seen = {}
33   result = []
34   for item in seq:
35       marker = idfun(item)
36       if marker in seen: continue
37       seen[marker] = 1
38       result.append(item)
39   return result
40
41def usage(a):
42  if a == 'gojob':
43    print a,'logs you in to a node where a job is running'
44  if a == 'topjob':
45    print a,'shows the system usage of a node where a job is running'
46   
47  print 'Usage:'
48  print a,'jobnumber [nodenumber]'
49  print 'where jobnumber is the number of the job'
50  print '      nodenumber is the rank number of the node allocated to the job'
51  print '      (default 0)'
52 
53me = sys.argv[0].split('/')[-1]
54print '['+me+']'
55p = PBSQuery()
56
57try:
58  j=sys.argv[1]
59except:
60  usage(me)
61  sys.exit(1)
62
63# check if numerical jobnumber. (Be aware: dependecy jobs have a '-')
64try:
65  nj = int(j.split('.')[0].split('-')[0]) 
66except:
67  usage(me)
68  sys.exit(1)
69
70if len(sys.argv) > 2:
71  try:
72    num = int(sys.argv[2])
73  except:
74    usage(me)
75    sys.exit(1)
76else:
77  num = 0
78
79job = p.getjob(j)
80
81try:
82  h = job['exec_host'][0]
83except:
84  print 'No such job:',j
85  sys.exit(1)
86
87hh = h.split('+')
88nodes=[]
89for h in hh:
90  nodes = nodes + [ h.split('/')[0]]
91
92nodes = uniq(nodes)
93print 'Job',j,'is running on',len(nodes),'nodes:'
94i=0
95for h in nodes:
96  print h,
97  i = i+1
98  if i > 7:
99    i=0
100    print
101if i != 0:
102  print
103
104if num >= len(nodes):
105  print 'No node number',num
106  sys.exit(1)
107
108if me == 'topjob':
109  user=job['Job_Owner'][0].split('@')[0]
110  print 'top for node #',num,':',nodes[num],'user:',user
111  sys.stdout.flush()
112  os.system('ssh '+nodes[num]+' top -n1 -b -u ' + user)
113
114if me == 'gojob':
115  user = os.getenv('USER')
116  print 'logging in to node #',num,':',nodes[num],'user:',user
117  sys.stdout.flush()
118  os.system('ssh -X '+nodes[num])
119
Note: See TracBrowser for help on using the repository browser.