I am new to bash script. I need to keep file for retention period of one month and archive other.
Example:
File format: WE20160225.log (20160225 YYYYMMDD)
Say in the directory /oracle/Sales
has 2 files:
WE20160130.log
WE20151201.log
I need to tar the WE20151201.log
But not WE20160130.log because the file is less than one month from now. How can I do this? (probably need to substring the filename)
I'm able to change directory but don't know what to do next. My logic is loop through the file and get the date from filename, then compare with current date.
I need to use the filename date, not the file modification date.
SALES_DIR="/oracle/sales/"
cd $SALES_DIR
find
to check on modification time (instead some number sequence that might, or might not be available as part of the filename and could be interpreted as a date? And then you create the tar file from the resulting file list.find
can be used, if not, some other technique is required).