This commit is contained in:
leo 2024-08-08 07:05:39 +05:00
parent 9e0caca46f
commit 45187f7385

View File

@ -1,33 +1,33 @@
#!/bin/bash
CRON_LIST=/data/config/$SRV_START_DIR/cron.cfg
CRON_LIST=/data/$SRV_START_DIR/config/cron.cfg
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT
trap 'echo -e "\033[31mcrom-list.sh: Something went wrong\033[0m"; exit 1' EXIT
set -e
export DEBIAN_FRONTEND=noninteractive
# Checking for the presence of the cron.list file
echo "Checking for the presence of the cron.cfg file..."
if [ ! -f $CRON_LIST ]; then
echo "cron.cfg file not found!"
exit 1
fi
# Reading current crontab jobs into a variable
echo "Reading current crontab jobs into a variable..."
current_crontab=$(crontab -l 2>/dev/null)
# Iterate through the lines of the cron.list file
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
# Checking if a job exists in the current crontab
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
# Adding a job to crontab
echo "Adding a job to crontab..."
(crontab -l; echo "$line") | crontab -
echo "Task added: $line"
fi