Last active
January 18, 2024 12:29
-
-
Save serg-kovalev/a8502ba876f27b4310e8fae5e0032daa to your computer and use it in GitHub Desktop.
Truncate log files (Linux/Macos), requires bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### you can add it to cron and execute on hourly/daily/weekly/monthly basis | |
### this script logs into cleanup_logs.log file | |
find /home /var/log -type f -name "*.log" -exec bash -c 'size=$(du -m "{}" | cut -f1); [ "$size" -gt 1 ] && truncate -s 1M "{}" && echo "{}"' \; >> cleanup_logs.log | |
echo "last started at $(date)" >> cleanup_logs.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment