#!/bin/bash CRON_LIST=/data/$SRV_START_DIR/config/cron.cfg trap 'echo -e "\033[31mcrom-list.sh: Something went wrong\033[0m"; exit 1' ERR set -e export DEBIAN_FRONTEND=noninteractive echo "Checking for the presence of the cron.cfg file..." if [ ! -f $CRON_LIST ]; then echo "cron.cfg file not found!" exit 1 fi echo "Reading current crontab jobs into a variable..." current_crontab=$(crontab -l 2>/dev/null || true) echo "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 echo "Checking if a job exists in the current crontab..." if echo "$current_crontab" | grep -Fq "$line"; then echo "The task already exists: $line" else echo "Adding a job to crontab..." (crontab -l 2>/dev/null || true; echo "$line") | crontab - echo "Task added: $line" fi done < "$CRON_LIST" trap - ERR echo "Cron jobs from $CRON_LIST added successfully"