Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 16th, 2012  |  syntax: None  |  size: 1.01 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env ruby19
  2.  
  3. class Job
  4.   def initialize(line)
  5.     @f = line.split
  6.   end
  7.  
  8.   def user
  9.     @f[1]
  10.   end
  11.  
  12.   def status
  13.     @f[2]
  14.   end
  15.  
  16.   def running?
  17.     status == 'RUN'
  18.   end
  19. end
  20.  
  21. stats = Hash.new {|h,k| h[k] = {:running => 0, :other => 0} }
  22. `bjobs -u all | grep -v JOBID`.each_line do |line|
  23.   j = Job.new(line)
  24.   if j.running?
  25.     stats[j.user][:running] += 1
  26.   else
  27.     stats[j.user][:other] += 1
  28.   end
  29. end
  30.  
  31. total_run    = 0
  32. total_others = 0
  33.  
  34. puts "-" * 80
  35. stats.each do |user, jobs|
  36.   printf "%8s"         % user
  37.   printf ": R{%3s}"     % jobs[:running]
  38.   printf ": O{%3s}" % jobs[:other]
  39.   printf ": T{%3s}\n" % (jobs[:other] + jobs[:running])
  40.   total_run    += jobs[:running]
  41.   total_others += jobs[:other]
  42. end
  43.  
  44. puts "-" * 80
  45. puts "Total (R)  : #{total_run}"
  46. puts "Total (O)  : #{total_others}"
  47. puts "      (R+O): #{total_others + total_run}"
  48.  
  49. puts "-" * 80
  50. a_hosts = `bjobs -u all | grep RUN | awk '{print $6}' | sort | uniq | wc -l`
  51. puts "# Active hosts: " + a_hosts