How can I get qstat
to give me full job names?
I know qstat -r
gives detailed information about the task, but it\'s too much and the resource r
Thanks to JLT for nice simple code. I've expanded it a bit to fit my needs and make it look nice.
Sample Output:
Job ID Job Name Owner Status
------ ------------------------------------ ------ ------
201716 AtacSilN100400K mtsige R
201771 IsoOnGrap400K mtsige R
202067 AtacOnSilica400K mtsige R
202100 AtacGrapN100400K mtsige R
202135 AtacOnSilc400K mtsige R
202145 AtacOnGrap400K mtsige R
202152 AtacOnGraphN3360K mtsige R
202161 AtacticSilicaN10 mtsige R
202163 AtacGrapN10 mtsige R
202169 AtacSilcN10 mtsige R
202192 wallpmma07 am110 R
202193 wallpmma03 am110 R
202194 att03wpm_95solps am110 R
202202 AtacticSilicaN3 mtsige R
203260 8test18_trop_2p ico R
203359 parseAll_Bob/Sub951By50/Cyl20A_atom1 oge1 R
203360 parseAll_Bob/Sub951By50/Cyl30A_atom1 oge1 R
203361 parseAll_Bob/Sub951By50/Cyl30A_atom2 oge1 R
Code:
#!/opt/bin/python3
import os
import xml.etree.ElementTree as ET
#Fields
fields=['Job_Id','Job_Name','Job_Owner','job_state']
names=['Job ID','Job Name','Owner','Status']
#Get job info
f = os.popen('qstat -x')
tree = ET.parse(f)
root = tree.getroot()
n_fields=len(fields)
jobs=[[job.find(field).text for field in fields] for job in root]
max_lengths=[len(name) for name in names]
sep=' '
#Identify max characer length per field
for j in jobs:
for i in range(n_fields):
#Chop off anything after and including '@' or '.' from all fields
if j[i].find('@')>0:
j[i]=j[i][:j[i].find('@')]
if j[i].find('.')>0:
j[i]=j[i][:j[i].find('.')]
if(len(j[i])>max_lengths[i]):
max_lengths[i]=len(j[i])
#Field names
for i in range(n_fields):
print('{s:^{length}}'.format(s=names[i],length=max_lengths[i]),end=sep)
print()
#Dashes
for i in range(n_fields):
print('-'*max_lengths[i],end=sep)
print()
#Jobs
for j in jobs:
for i in range(n_fields):
if j[i].find('@')>0:
j[i]=j[i][:j[i].find('@')]
print('{s:<{length}}'.format(s=j[i],length=max_lengths[i]),end=sep)
print()