2024-07-27 04:15:43 +05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-08-08 07:05:39 +05:00
|
|
|
CRON_LIST=/data/$SRV_START_DIR/config/cron.cfg
|
2024-07-27 04:15:43 +05:00
|
|
|
|
2024-08-14 10:49:55 +05:00
|
|
|
trap 'echo -e "\033[31mcrom-list.sh: Something went wrong\033[0m"; exit 1' ERR
|
2024-07-27 04:15:43 +05:00
|
|
|
set -e
|
|
|
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
2024-08-08 07:05:39 +05:00
|
|
|
echo "Checking for the presence of the cron.cfg file..."
|
2024-07-27 04:15:43 +05:00
|
|
|
if [ ! -f $CRON_LIST ]; then
|
2024-08-08 06:37:47 +05:00
|
|
|
echo "cron.cfg file not found!"
|
2024-07-27 04:15:43 +05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-08 07:05:39 +05:00
|
|
|
echo "Reading current crontab jobs into a variable..."
|
2024-08-18 11:07:02 +05:00
|
|
|
current_crontab=$(crontab -l 2>/dev/null || true)
|
2024-07-27 04:15:43 +05:00
|
|
|
|
2024-08-08 07:05:39 +05:00
|
|
|
echo "Iterate through the lines of the cron.list file..."
|
2024-07-27 04:15:43 +05:00
|
|
|
while IFS= read -r line; do
|
|
|
|
# Skip blank lines and comments
|
|
|
|
if [[ -z "$line" || "$line" == \#* ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-08-08 07:05:39 +05:00
|
|
|
echo "Checking if a job exists in the current crontab..."
|
2024-07-27 04:15:43 +05:00
|
|
|
if echo "$current_crontab" | grep -Fq "$line"; then
|
|
|
|
echo "The task already exists: $line"
|
|
|
|
else
|
2024-08-08 07:05:39 +05:00
|
|
|
echo "Adding a job to crontab..."
|
2024-08-18 11:07:02 +05:00
|
|
|
(crontab -l 2>/dev/null || true; echo "$line") | crontab -
|
2024-07-27 04:15:43 +05:00
|
|
|
echo "Task added: $line"
|
|
|
|
fi
|
|
|
|
done < "$CRON_LIST"
|
|
|
|
|
2024-08-14 10:49:55 +05:00
|
|
|
trap - ERR
|
|
|
|
echo "Cron jobs from $CRON_LIST added successfully"
|