I have to make a bash script that do a gzip of a file if is older than 60 days, and move it in a subdir which name is the beginning of the filename. Here an example of the files I have to work with:
-rw-r--r-- 1 X X 0 2012-10-15 11:19 glux21-x1.csv
-rw-r--r-- 1 X X 0 2012-10-15 11:19 GLUX21-x34.csv
-rw-r--r-- 1 X X 0 2012-10-15 11:19 glux226.csv
-rw-r--r-- 1 X X 0 2012-10-15 11:19 glux228.csv
-rw-r--r-- 1 X X 0 2012-10-15 11:19 glux230.csv
-rw-r--r-- 1 X X 0 2012-10-15 11:19 glux232.csv
-rw-r--r-- 1 X X 0 2012-10-15 11:19 glux234.csv
-rw-r--r-- 1 X X 0 2012-10-15 11:19 glux236.csv
-rw-r--r-- 1 X X 0 2012-10-15 11:19 glux255.csv
So, for example, the glux21-x1.csv should be gzipped and moved in the glux21 subdir, as for the GLUX21-x34.csv file. The glux255.csv should go in the glux255 subdir.
logrotate
? It could do a lot of what you're after and is flexible (eg. with thelastaction
directive). – sr_ Oct 15 '12 at 10:23