schedule work fine for this.
You could probably do all in Python,and drop the the shell script.
Here a example of making a file then delete,
You could probably do all in Python,and drop the the shell script.
Here a example of making a file then delete,
run_sh
example on how to call shell script with subprocess.import schedule import time, os import subprocess def make_file(): fn = 'test.out' open(fn, 'a').close() print(f'Making <{fn}>') def del_file(): try: fn ='test.out' os.remove(fn) print(f"Removed <{fn}>") except FileNotFoundError: print(f'Could not find <{fn}>') def run_sh(): '''Example running shell script''' subprocess.run(['bash', 'start.sh']) schedule.every(8).seconds.do(make_file) schedule.every(12).seconds.do(del_file) while True: schedule.run_pending() time.sleep(1)
Output:λ python remove_file.py
Making <test.out>
Removed <test.out>
Making <test.out>
Removed <test.out>
Making <test.out>
Making <test.out>
Removed <test.out>
Making <test.out>