walking a file path and compressing files (except for today)
How would I got about using a bash script to walk a few file paths and compress files which are not compressed? Maybe run a daily cron job and archive all logs except for today.
file structure as follows: /var/log/hosts/192.168.1.1/2008/11/17/log /var/log/hosts/192.168.1.1/2008/11/18/log /var/log/hosts/192.168.1.2/2008/11/17/log /var/log/hosts/192.168.1.2/2008/11/18/log /var/log/hosts/192.168.1.3/2008/11/17/log /var/log/hosts/192.168.1.3/2008/11/18/log I can walk the path as follows: find /var/log/hosts -d | sed '1d' regards |
You can check if the file is compressed in a number of ways, that range from the easiest checks using the file extensio to the output of the command file and many others. You can also instruct find to find only files newer than a given date. Check -mtime -ctime and -atime.
I would also check logrotate. It's what most people use and it's designed exactly for this task. |
Thanks for the response.
The following will produce a list of all files. Code:
I just need the file replace in the same location with the compressed version. Nothing fancy. Please forgive me as I am a newbie. regards, |
I have managed to generate a file list of paths to the files I need to compress. Now I need to step though each path and filename, and compress the file.
The 2nd loop does not work yet, so its just an analogy of what I am trying to do. Code:
for path in `find /var/log/hosts/*/2008/11/* -type f`; do |
All times are GMT -5. The time now is 01:11 AM. |