Hey everyone,
We've updated our free script for automating log maintenance on Enhance servers. This version addresses a key issue reported by some users, log files were losing their original ownership and getting set to root after truncation.
The updated script now preserves the original file ownership after truncation using sponge, with no added overhead.
If you're using the old version, we recommend switching to this one to avoid potential permission issues:
https://gist.github.com/cPFence/6b667f2404479a75cd9614973ea28c5f
If you're using a custom version, you can just update this part:
# Truncate error logs > 5 MB while preserving ownership
/usr/bin/find /var/www \
-path "*/cpf_logs/*" -prune -o \
\( -name "*.log" -o -name "*_log" \) -size +5M -type f -exec sh -c '
for file; do
owner=$(stat -c "%u:%g" "$file") # save UID:GID
tail -c 5M "$file" | /usr/bin/sponge "$file"
chown "$owner" "$file" # restore ownership
done
' sh {} +
This will make sure to preserve ownership and skip LogSpot logs (cpf_logs).
Give it a go and let us know how it goes.
Cheers,
The cPFence Team