#!/usr/bin/env python ''' This script is used to 1) record the job_ID and directories 2) print the job path from the job_ID ''' from subprocess import Popen, PIPE import numpy as np import sys
defget_id(): list_j = [] # list for the job_ID process = Popen(['squeue', '-lu', 'gkzshpc101'], stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() list_out = stdout.split('\n')[2:] for i inrange(0, len(list_out)-1): list_j.append(list_out[i].split()[0]) return list_j
defget_dir(job_id): job_dir = None command = 'scontrol show job ' + job_id process1 = Popen(command, shell = True, stdout=PIPE, stderr=PIPE) stdout1, stderr1 = process1.communicate() for i in stdout1.split('\n'): if'WorkDir'in i: #job_dir.append(i.split('=')[1]) job_dir = i.split('=')[1] return job_dir
id_dict = {} withopen('/public1/home/gkzshpc101/bin/job_check/job_list.txt', 'a+') as file_in: lines = file_in.readlines() for line in lines: key = line.split(':')[0] value = line.split(':')[1] id_dict[key] = value
list_j = get_id()
for i in list_j: if i notin id_dict.keys(): id_dict[i] = get_dir(i) file_in.write(i + ':' + get_dir(i) + '\n')
job_id = sys.argv[1]
for i in id_dict.keys(): if job_id in i: print(id_dict.get(i).strip())