Bash Script to Compress / Transfer / Remove Log Files
Posted
by
Jason
on Server Fault
See other posts from Server Fault
or by Jason
Published on 2014-08-18T14:36:20Z
Indexed on
2014/08/18
16:29 UTC
Read the original article
Hit count: 371
I am currently using chronolog to set log file names for Apache with date. They are in the following format:
/WEB/LOGS/APACHE_ACCESS_YYYY-MM-DD.log /WEB/LOGS/APACHE_ERROR_YYYY-MM-DD.log
I would like to have a script that runs on the first of every month and compresses the log files from the previous month, transfers them to another host (via SCP) and then deletes the compressed file.
find . -name '*.log' -mtime +1 -type f
I've found several examples like the one above that allow you to select files x days old, but I need all files from the previous month. I am the first to admit my bash scripting skills are weak so would really appreciate any help and guidance.
© Server Fault or respective owner