Identify log files based on time stamp,zip and then copy..HELP

Hi All,
PFB is a requirement. I am new to shell scripting. So plz help. It would be highly appreciated.

  1. choose all the log files based on a particular date (files location is '/test/domain')--i.e,we should choose all the files that are modified on 29th November, neither 28th nor 30th
  2. zip the files (concatenating the files into a single one is OK)
  3. name the zip file as the current date (when the shell script is run)
  4. copy the zip file to backup_log folder (location would be '/test/domain/backup_log')
    -----------------------------------------------------------------------
    example of a log file name is application.log.1, application.log.2 and so on

---------- Post updated at 02:50 PM ---------- Previous update was at 02:48 PM ----------

by the way it is ksh UNIX environ.

here is a ksh script that uses awk and gzip (this will give a GNU zip file not pkzip). Do you have a pkzip program installed on your UNIX environ? If you are on solaris you may have the /usr/local/zip command.

backup_domain.sh

#/bin/ksh
month=$1
day=$2
cd /test/domain
files=`ls -l . |  awk ' $1 ~ /^[^d]/ && tolower($6$7) ~ /'${month}${day}'/ { print $9 }'`
[ -n "$files" ] && cat $files | gzip -9c > backup_log/`date +%Y_%m_%d`.log.gz

Call it like this

$ backup_domain.sh nov 29

thanks chubler. actually the script needs to pick up all the log files created on the previous day (for example, if the script is run on 28th, it should pick up log files with timestamp of 27th). And it should be free of any argument so that the script running can be automated.

Also, uaing gzip is ok.

Thanks
Nil

That makes more sense. Do you have GNU date (supports "date --date -1day").

This is also really dependant on the format of ls, I've tested on AIX and my ls output looks like this:

-rwxr-xr-x    1 chubler users           330 Oct 22 09:01 test
-rw-r--r--    1 chubler users          1301 Oct 13 07:40 test.dat
-rw-r--r--    1 chubler users            38 Oct 29 07:49 test1
drwxr-xr-x    2 chubler users           256 Nov 18 09:29 testdir
-rwxr-xr-x    1 chubler users           400 Oct 29 07:34 testi

If all is OK this should work for GNU date:

#/bin/ksh
when=`date --date -1day +%b%d`
cd /test/domain
files=`ls -l . | awk ' $1 ~ /^[^d]/ && $6$7 ~ /'${when}'/ { print $9 }'`
[ -n "$files" ] && cat $files | gzip -9c > backup_log/`date +%Y_%m_%d`.log.gz

Otherwise this might do it (Adjust +14 for you timezone, we want to get date reporting the same time but with yesterday's date):

#/bin/ksh
when=`TZ=GMT+14 date +%b%d`
cd /test/domain
files=`ls -l . |  awk ' $1 ~ /^[^d]/ && $6$7 ~ /'${when}'/ { print $9 }'`
[ -n "$files" ] && cat $files | gzip -9c > backup_log/`date +%Y_%m_%d`.log.gz