#!/usr/bin/env python3 from os import walk from datetime import datetime week_day = datetime.now().isocalendar().week week_cert = f'certificate_{week_day}.crt' for p, d, f in walk('pki/x509'): if not d and not f: print('empty dir, you can remove it: ', p) if not f: continue if f == ['serial_number']: continue if not p.endswith('/ca') and not p.endswith('/server') and not p.endswith('/client'): print('unknown directory: ', p) continue if week_cert in f: continue for ff in f: if ff.startswith('certificate_') and ff.endswith('.crt'): print(f'old certificat in: ', p) break else: print('cannot find certificat in: ', p)