need to zip all the files excluding todays file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers need to zip all the files excluding todays file
# 1  
Old 06-21-2011
need to zip all the files excluding todays file

HI All,

At present in my server the log folder was filled up and causing memory issue.
So I am planning to write a script in such a way that the files which are older than 30 days will be deleted and also need to find the files which were not compressed and need to compress this file. Compression will exclude if the file was created on the same day.

I am new to Unix .Please bear me.
# 2  
Old 06-21-2011
The find command has a -mtime option which allows you specify a max or min last modification time of files to be reported.

I would be inclined to do this in 2 sweeps, though I'm sure someone will offer a better method, so I'd do something like
WARNING: Untested code, replace the gzip and rm commands with 'echo "We would zip $i" ' and 'echo "We would delete $i" ' first to ensure it does what you require
Code:
for i in $(find /var/myapp/logs/ -mtime +1 | grep -vE '\.gz$')
   do
   gzip $i
done
for i in $(find /var/myapp/logs/ -mtime +30)
   do
      rm $i
done

this assumes that the log rollover will happen within a 24 hour period.

Last edited by Skrynesaver; 06-21-2011 at 07:35 AM.. Reason: Added warning in case OP tried command without testing
# 3  
Old 06-29-2011
Thanks for your response.

WE have 2 type of files in log folder one is server.log and another one is boot.log

I only want the above script to work for server.log not on boot.log

How can I exclude this?

Thanks.
Arumilli.
# 4  
Old 06-30-2011
use -name in find command

Code:
 
find /var/myapp/logs/ -mtime +1 -name "server.log*"

# 5  
Old 06-30-2011
Thanks for your reply..

WE have file created on Jun 28 and Jun 29. when I given
find /apps/bcc/jboss/server/atgpub/log -mtime +1 it returning upto Jun27.

Correct me +1 means 1 day before. I am executing command on Jun 30. SO it must retrieve the Jun28 and Jun 29

when I execute ll var/log/jboss
Code:
-rw-rw-r-- 1 jboss jboss     8476 Apr 11 12:47 boot.log.gz
-rw-rw-r-- 1 jboss jboss  2207218 Jun 30 09:56 server.log
-rw-rw-r-- 1 jboss jboss   155706 May 30 23:59 server.log.2011-05-30.gz
-rw-rw-r-- 1 jboss jboss    36393 May 31 23:59 server.log.2011-05-31.gz
-rw-rw-r-- 1 jboss jboss   202830 Jun  1 23:58 server.log.2011-06-01.gz
-rw-rw-r-- 1 jboss jboss   185878 Jun  2 23:57 server.log.2011-06-02.gz
-rw-rw-r-- 1 jboss jboss   185110 Jun  3 23:57 server.log.2011-06-03.gz
-rw-rw-r-- 1 jboss jboss   158412 Jun  4 23:59 server.log.2011-06-04.gz
-rw-rw-r-- 1 jboss jboss   187039 Jun  5 23:59 server.log.2011-06-05.gz
-rw-rw-r-- 1 jboss jboss   187333 Jun  6 23:59 server.log.2011-06-06.gz
-rw-rw-r-- 1 jboss jboss   169367 Jun  7 23:59 server.log.2011-06-07.gz
-rw-rw-r-- 1 jboss jboss   172313 Jun  8 23:59 server.log.2011-06-08.gz
-rw-rw-r-- 1 jboss jboss   129330 Jun  9 23:58 server.log.2011-06-09.gz
-rw-rw-r-- 1 jboss jboss   187479 Jun 10 23:59 server.log.2011-06-10.gz
-rw-rw-r-- 1 jboss jboss   192455 Jun 11 23:59 server.log.2011-06-11.gz
-rw-rw-r-- 1 jboss jboss   196684 Jun 12 23:58 server.log.2011-06-12.gz
-rw-rw-r-- 1 jboss jboss   195392 Jun 13 23:59 server.log.2011-06-13.gz
-rw-rw-r-- 1 jboss jboss   196948 Jun 14 23:59 server.log.2011-06-14.gz
-rw-rw-r-- 1 jboss jboss   196904 Jun 15 23:59 server.log.2011-06-15.gz
-rw-rw-r-- 1 jboss jboss   188622 Jun 16 23:57 server.log.2011-06-16.gz
-rw-rw-r-- 1 jboss jboss   175597 Jun 17 23:59 server.log.2011-06-17.gz
-rw-rw-r-- 1 jboss jboss   188572 Jun 18 23:59 server.log.2011-06-18.gz
-rw-rw-r-- 1 jboss jboss   190387 Jun 19 23:59 server.log.2011-06-19.gz
-rw-rw-r-- 1 jboss jboss   193698 Jun 20 23:59 server.log.2011-06-20.gz
-rw-rw-r-- 1 jboss jboss   202076 Jun 21 23:59 server.log.2011-06-21.gz
-rw-rw-r-- 1 jboss jboss   213279 Jun 22 23:59 server.log.2011-06-22.gz
-rw-rw-r-- 1 jboss jboss   192047 Jun 23 23:58 server.log.2011-06-23.gz
-rw-rw-r-- 1 jboss jboss   192208 Jun 24 23:58 server.log.2011-06-24.gz
-rw-rw-r-- 1 jboss jboss   191900 Jun 25 23:59 server.log.2011-06-25.gz
-rw-rw-r-- 1 jboss jboss   175761 Jun 26 23:59 server.log.2011-06-26.gz
-rw-rw-r-- 1 jboss jboss   188136 Jun 27 23:58 server.log.2011-06-27.gz
-rw-rw-r-- 1 jboss jboss 13812475 Jun 28 23:58 server.log.2011-06-28
-rw-rw-r-- 1 jboss jboss  2950216 Jun 29 23:59 server.log.2011-06-29

when use find /apps/bcc/jboss/server/atgpub/log -mtime +1

Code:
/apps/bcc/jboss/server/atgpub/log/server.log.2011-05-31.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-09.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-07.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-10.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-05-30.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-01.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-23.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-06.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-12.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-27.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-26.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-19.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-15.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-04.gz
/apps/bcc/jboss/server/atgpub/log/boot.log.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-05.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-24.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-02.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-21.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-25.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-14.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-16.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-18.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-03.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-13.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-11.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-20.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-08.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-17.gz
/apps/bcc/jboss/server/atgpub/log/server.log.2011-06-22.gz

Clearly missing the red color files.

Can anyone help me out please.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find todays files

I am trying to find todays files only in the "root directories like /etc, /opt etc. I do not want to search in my home directory or any of its subdirectories. That's hard because a directory listing does not show the year? -rw------- 1 andy andy 22487 Oct 12 13:40 .xsession-errors ... (8 Replies)
Discussion started by: drew77
8 Replies

2. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

3. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

4. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

5. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

6. Shell Programming and Scripting

Count for only todays files.

Hi, I unable to find the direct command get the total count for the below files with today date. ls -lrt c90.txt n5.txt t1.txt k3.txt h9.txt s1.txt n2.txt a123.txt -rw-rw-r-- kkk klkl 980 Apr 26 19:00 c90.txt -rw-rw-r-- kkk klkl 80 Apr 26 19:00 n5.txt -rw-rw-r-- kkk klkl 12890 Apr 26... (3 Replies)
Discussion started by: onesuri
3 Replies

7. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

8. Shell Programming and Scripting

zip all of files except last file

hi, I try to write a script to zip archivelog files in arch fold except not zip last archivelog file since it database may be still using the last file here is my script. when I run the script, I get error messages. could you please advise/correct my script in detail what it could be wrong, I am... (9 Replies)
Discussion started by: percvs88
9 Replies

9. UNIX for Advanced & Expert Users

listing files excluding files from control file

I have a directory named Project.I have a control file which contains valid list of files.I would like list the files from directory Project which contains files other than listed in the control file. Sample control file: TEST SEND SFFFILE CONTL The directory contains followign... (15 Replies)
Discussion started by: ukatru
15 Replies

10. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies
Login or Register to Ask a Question