#!/usr/bin/bash # -delete option implicitly uses -depth, which traverse folders with DFS # (beginning with folder's content, ending with folder itself) # so, if old folder contains old files, "directory is not empty" error won't happen. # Old folder may not be deleted only if contains recently modified files su -s /bin/bash ossec -c 'find -P /var/ossec/logs/{alerts/*,archives/*,firewall/*} -xdev -mtime +2 -not -name alerts.json -delete' >/dev/null 2>&1 exit 0