#!/usr/bin/python3 import os import sys import shutil import time import random import threading import subprocess ev = threading.Event() def worker(): path = "/mnt/first" dest = os.path.join(path, "dest") fordel = os.path.join(path, "fordel") while True: try: if os.path.islink(dest): os.unlink(dest) elif os.path.isdir(dest): shutil.rmtree(dest) if os.path.isdir(fordel): shutil.rmtree(fordel) os.mkdir(dest) ev.set() os.rename(dest, fordel) os.symlink("/tmp", dest) ev.clear() except Exception as err: print(err) def main(): threading.Thread(target=worker, daemon=True).start() # Use smbclient to force use of separate smbd process as well as to require # resolving of symlink on server cmd = [ "bin/smbclient", "-U", "johndoe", r"\\172.17.0.2\data", "pass", "-", ] with subprocess.Popen(cmd, stdin=subprocess.PIPE, universal_newlines=True) as proc: while True: ev.wait() proc.stdin.write("mkdir dest/shouldnotexist.{}\n".format(time.time())) proc.stdin.flush() if __name__ == "__main__": main() # vim: set sw=2 sts=2 et :