From 11d5c2af586a55b7ee14ec3947da2d97b85abd97 Mon Sep 17 00:00:00 2001 From: NiceDevil Date: Sun, 26 Jan 2025 08:57:41 +0000 Subject: [PATCH] Update Proxmox/pbs_logrotate.sh --- Proxmox/pbs_logrotate.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Proxmox/pbs_logrotate.sh b/Proxmox/pbs_logrotate.sh index f5bd452..98d20fe 100644 --- a/Proxmox/pbs_logrotate.sh +++ b/Proxmox/pbs_logrotate.sh @@ -41,7 +41,7 @@ cron_command_suffix=" -type f -exec mv {} $backup_directory/ \; && /usr/bin/find cron_command="$cron_command_base$days_to_keep$cron_command_suffix" cron_job="0 3 * * * $cron_command" -# Check if a similar cron job exists with a different number of days +# Check if a similar cron job exists existing_cron=$(crontab -l 2>/dev/null | grep -F "$cron_command_base") if [[ -n "$existing_cron" ]]; then existing_days=$(echo "$existing_cron" | grep -oP "\+\d+" | head -n 1 | tr -d '+') @@ -67,8 +67,8 @@ if [[ -n "$existing_cron" ]]; then fi fi -# Preserve existing crontab and add the new job at the bottom -current_crontab=$(crontab -l 2>/dev/null | grep -vF "$cron_job") +# Add the new job if no existing job was found +current_crontab=$(crontab -l 2>/dev/null | grep -vF "$cron_command_base") echo -e "$current_crontab\n$cron_job" | sed '/^$/d' | crontab - # Check if the cron job was added successfully @@ -82,4 +82,4 @@ else exit 1 fi -exit 0 \ No newline at end of file +exit 0