Tuesday, March 5, 2013

Reading/Writing xlsx File In Python

I'm using the python library openpyxl.
The below shows an example of how to iterate thru cells ...


#!/usr/bin/env python

import openpyxl
from pprint import pprint

wb = openpyxl.reader.excel.load_workbook('test.xlsx')
s = wb.get_sheet_by_name(name='Sheet1')

d = s.calculate_dimension()

r = s.range(d)
print "Range:" + str(r)
for row in r:
   for cell in row:
      print cell.get_coordinate()
      print cell.value
If you need help, u can use the python interactive session:-
%python
>>> import openpyxl
>>> help(openpyxl.reader.excel)
>>> wb = openpyxl.reader.excel.load_workbook('test.xlsx')
>>> help(wb)
>>> ws = wb.get_sheet_by_name(name='Sheet1')
>>> help(ws)
>>> cell = ws.cell(row=0, column=0)
>>> help(cell)

Sunday, March 3, 2013

How To Kill A Bunch Of My LSF Jobs

I want to list out all my current jobs in lsf:-

%bjobs
JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME
4883896 yltan RUN ice_arc_sm pg-yltan-l pg-iccf0082 *eep 11111 Mar 1 15:37
4883898 yltan RUN ice_arc_sm pg-yltan-l pg-iccf0039 *eep 11111 Mar 1 15:37
4883974 yltan RUN ice_arc_sm pg-yltan-l pg-iccf0079 *eep 11111 Mar 1 15:45
4883975 yltan RUN ice_arc_sm pg-yltan-l pg-iccf0082 *eep 11111 Mar 1 15:45
4883976 yltan PEND ice_arc_sm pg-yltan-l pg-iccf0035 *eep 11111 Mar 1 15:45
4883977 yltan PEND ice_arc_sm pg-yltan-l pg-iccf0039 *eep 11111 Mar 1 15:45




Killing All of the listed jobs 


%bjobs | awk '$1 ~ /^[0-9]/ {print $1}' | xargs bkill
Job <4883896> is being terminated
Job <4883898> is being terminated
Job <4883974> is being terminated
Job <4883975> is being terminated
Job <4883976> is being terminated
Job <4883977> is being terminated



Killing All of the listed jobs, with a few exceptions

%bjobs | awk '$1 ~ /^[0-9]/ && $1 !~ /(4883896|4883898)/ {print $1}' | xargs bkill
Job <4883974> is being terminated
Job <4883975> is being terminated
Job <4883976> is being terminated
Job <4883977> is being terminated

How To Bypass Kerberos(kinit) Authentication

Whenever you try to setuid and impersonate as someone else to run something, it is very likely that you will run into kerberos/kinit issues....