Update Proxmox/pbs_logrotate.sh

This commit is contained in:
2025-01-26 08:57:41 +00:00
parent 71407eb207
commit 11d5c2af58

View File

@@ -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_command="$cron_command_base$days_to_keep$cron_command_suffix"
cron_job="0 3 * * * $cron_command" 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") existing_cron=$(crontab -l 2>/dev/null | grep -F "$cron_command_base")
if [[ -n "$existing_cron" ]]; then if [[ -n "$existing_cron" ]]; then
existing_days=$(echo "$existing_cron" | grep -oP "\+\d+" | head -n 1 | tr -d '+') existing_days=$(echo "$existing_cron" | grep -oP "\+\d+" | head -n 1 | tr -d '+')
@@ -67,8 +67,8 @@ if [[ -n "$existing_cron" ]]; then
fi fi
fi fi
# Preserve existing crontab and add the new job at the bottom # Add the new job if no existing job was found
current_crontab=$(crontab -l 2>/dev/null | grep -vF "$cron_job") current_crontab=$(crontab -l 2>/dev/null | grep -vF "$cron_command_base")
echo -e "$current_crontab\n$cron_job" | sed '/^$/d' | crontab - echo -e "$current_crontab\n$cron_job" | sed '/^$/d' | crontab -
# Check if the cron job was added successfully # Check if the cron job was added successfully