#!/usr/bin/env python # # et_mon_dir.py /tmp/et_sys_test "/gluex/data/rawdata/curr/rawdata/active/RunPeriod-2018-08/rawdata/Run*/*.evio" # # # import subprocess import time import glob import sys import os if len(sys.argv) !=3 : print '' print 'Usage:' print ' et_mon_dir.py et_file regexp' print '' print 'where "et_file" is something like /tmp/et_sys_monitoring' print 'and regexp gives a file pattern like:' print '' print ' "/gluex/data/rawdata/curr/rawdata/active/RunPeriod-2018-08/rawdata/Run051739/*.evio"' print '' print '(remember the quotes if using a wildcard!)' print '' sys.exit(0) et_file = sys.argv[1] mon_pat = sys.argv[2] et_prescale = '5' #base_dir = os.path.dirname(mon_pat) print 'mon_pat = ' + mon_pat #print 'base_dir = ' + base_dir last_file ='' while True: #if ! os.path.exists(base_dir): break files = glob.glob(mon_pat) files.sort(key=os.path.getmtime) print 'Found %d files matching %s' % (len(files), mon_pat) if len(files)>=2: most_recent_file = str(files[-2]) if most_recent_file != last_file: cmd = ['file2et', '-f', et_file, '-s', et_prescale, most_recent_file] print ' '.join(cmd) subprocess.call(cmd) last_file = most_recent_file time.sleep(2.0) print '' #print 'Directory ' + base_dir + ' has disappeared. Stopping'