diff --git a/Proxmox/pbs_logrotate.sh b/Proxmox/pbs_logrotate.sh index e01deb3..bb9ddcd 100644 --- a/Proxmox/pbs_logrotate.sh +++ b/Proxmox/pbs_logrotate.sh @@ -36,7 +36,7 @@ fi log_directory="/var/log/proxmox-backup" backup_directory="/var/log/proxmox-backup-backup" mkdir -p "$backup_directory" -cron_command="find $log_directory -mtime +$days_to_keep -type f -exec mv {} $backup_directory/ \; && find $backup_directory -mtime +30 -type f -exec rm {} +" +cron_command="/usr/bin/find $log_directory -mtime +$days_to_keep -type f -exec mv {} $backup_directory/ \; && /usr/bin/fin $backup_directory -mtime +30 -type f -exec rm {} +" cron_job="0 3 * * * $cron_command" # Check if the cron job already exists @@ -46,8 +46,9 @@ if [[ -n "$existing_cron" ]]; then exit 0 fi -# Add the cron job to the user's crontab -(crontab -l 2>/dev/null; echo "$cron_job") | crontab - +# Preserve existing crontab and add the new job +current_crontab=$(crontab -l 2>/dev/null) +echo -e "$current_crontab\n$cron_job" | awk 'NF' | sort -u | crontab - # Check if the cron job was added successfully if [[ $? -eq 0 ]]; then