Cron system based on python module pycron and command tool tmux. For firs you must create tmux session fro pycron script cron.py
and run in tmux terminal this script
$ sudo apt install tmux
$ tmux new-session -s parser
$ source ./venv/bin/activate
$ python cron.py
All code files
import pycron
import time
from subprocess import call
import shlex
while True:
if pycron.is_now('0 */2 * * *'): # True Every 2 h
print('running backup')
call(shlex.split('bash ./cron.sh'))
time.sleep(60) # The process should take at least 60 sec
# to avoid running twice in one minute
else:
time.sleep(15) # Check again in 15 seconds
#!/bin/bash
source ./venv/bin/activate
python ./script.py
import datetime
import glob
import os
######
dir = "./test/"
for zippath in glob.iglob(os.path.join(dir, '*.txt')):
os.remove(zippath)
######
current_date_and_time = datetime.datetime.now()
current_date_and_time_string = str(current_date_and_time)
extension = ".txt"
file_name = './test/' + current_date_and_time_string + extension
file = open(file_name, 'w')
file.close()