#! /usr/bin/python3 -Es import io import os import subprocess import sys import tempfile sge_root = os.environ.get('SGE_ROOT', '/var/lib/gridengine') sge_cell = os.environ.get('SGE_CELL', 'default') account_file = 'common/accounting' logpath = os.path.join(sge_root, sge_cell, account_file) with open(logpath, 'rb') as logfile: logfile.seek(-400 * 45000 * 7, os.SEEK_END) # Ignore first line as it may be onlym part of a line logfile.readline() with tempfile.TemporaryDirectory() as new_sge_root: new_logpath = os.path.join(new_sge_root, sge_cell, account_file) os.makedirs(os.path.dirname(new_logpath)) for fname in os.listdir(os.path.dirname(logpath)): os.symlink( os.path.join(os.path.dirname(logpath), fname), os.path.join(os.path.dirname(new_logpath), fname)) os.remove(new_logpath) os.mkfifo(new_logpath) real_qacct = subprocess.Popen( ['/usr/bin/qacct'] + sys.argv[1:], env=dict(os.environ, SGE_ROOT=new_sge_root)) with open(new_logpath, 'wb') as new_logfile: while real_qacct.poll() is None: data = logfile.read(io.DEFAULT_BUFFER_SIZE) if not data: break new_logfile.write(data) sys.exit(real_qacct.wait())