utils/cron-list.sh

37 lines
881 B
Bash
Raw Normal View History

2024-07-27 04:15:43 +05:00
#!/bin/bash
2024-08-08 06:37:47 +05:00
CRON_LIST=/data/config/$SRV_START_DIR/cron.cfg
2024-07-27 04:15:43 +05:00
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
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
# 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."