Cronjob that only runs if not already running - CloudCommandos/JohnChan GitHub Wiki
Assume you want to run /root/myjob.sh every 3 hours.
Install flock
apt install util-linux
crontab -e
0 */3 * * * /usr/bin/flock -n /tmp/myjob.lockfile /bin/bash -c "cd /root;./myjob.sh > $(date '+%Y-%m-%d-%H_%M_%S').txt;"