#!/bin/bash CRON_LIST=/data/config/$SRV_START_DIR/cron.cfg trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT set -e export DEBIAN_FRONTEND=noninteractive # Checking for the presence of the cron.list file if [ ! -f $CRON_LIST ]; then echo "cron.cfg file not found!" exit 1 fi # Reading current crontab jobs into a variable current_crontab=$(crontab -l 2>/dev/null) # Iterate through the lines of the cron.list file while IFS= read -r line; do # Skip blank lines and comments if [[ -z "$line" || "$line" == \#* ]]; then continue fi # Checking if a job exists in the current crontab if echo "$current_crontab" | grep -Fq "$line"; then echo "The task already exists: $line" else # Adding a job to crontab (crontab -l; echo "$line") | crontab - echo "Task added: $line" fi done < "$CRON_LIST" trap - EXIT echo "Cron add ok."