Skip to content

Instantly share code, notes, and snippets.

@bcbwilla
Last active December 19, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcbwilla/5986535 to your computer and use it in GitHub Desktop.
Save bcbwilla/5986535 to your computer and use it in GitHub Desktop.
This script is an improved version of the PBS 'qstat' command that prints out only USEFUL job information (like the FULL name) in a readable way. All of the output of the command 'qstat -f' is captured and organized, so it would be very easy to print out additional info by modifying the last loop of the script.
#! /usr/bin/python
#
# This script is an improved version of the 'qstat' command
# that prints out only USEFUL information (like the job's
# FULL name) in a readable way.
#
# All of the output of the command 'qstat -f' is captured
# and organized, so it would be very easy to print out
# additional info by modifying the last loop of the script.
#
import subprocess
# get user name
user = subprocess.check_output(['whoami']).strip()
# get all jobs data
out = subprocess.check_output(['qstat','-f'])
lines = out.split('\n')
# build list of jobs, each job is a dictionary
jobs = []
for line in lines:
if "Job Id:" in line: # new job
job = {}
s = line.split(":")
job_id = s[1].split('.')[0].strip()
job[s[0].strip()] = job_id
if '=' in line:
s = line.split("=")
job[s[0].strip()] = s[1].strip()
elif line == '':
jobs.append(job)
# print out useful information about user's jobs
print "\n " + user + "'s jobs:\n"
for job in jobs:
if job['Job_Owner'].split('@')[0] == user:
print " " + job['Job_Name']
print " Id: " + job['Job Id']
print " Wall time: " + job['resources_used.walltime']
print " State: " + job['job_state']
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment