Compressing previous log automatically


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compressing previous log automatically
# 1  
Old 10-08-2012
Compressing previous log automatically

I want to create a script that will zip the previous log.

Example.

abc.log.2012.12.02
abc.log.2012.12.01.gzip
abc.log

If today is 2012.12.03 , my current log is abc.log and my previous date is 2012.12.02, i want abc.log.2012.12.02 to compress everytime I run the script.

I can manually run compress the file
gzip abc.log.2012.12.02 but I want the log to automate every 2am in the morning.
Every 1200midnight the file is rotating and it creates a previous date, and I want this previous date file to be compress.

I now how to use the cronjob but i dont have script to do it. Please help.
# 2  
Old 10-08-2012
You don't need a script for this. You can put this entry in cron: gzip /home/logs/myApp/abc.log.$(date -d "-1 day" +%Y.%m.%d)
This User Gave Thanks to balajesuri For This Post:
# 3  
Old 10-08-2012
Code:
 
#!/bin/bash
YEST=`TZ="GMT+24" date +'%Y.%m.%d'`
echo "Yesterday : $YEST"
#gzip the Yesterday file
gzip -f abc.log.${YEST}

if you have gnu date, then you can use it as below

Code:
 
YEST=$(date -d "yesterday" +%Y.%m.%d)

# 4  
Old 10-08-2012
Can't you compress the file in the same job that it's created in?
# 5  
Old 10-08-2012
Don't you have logrotate (or something alike) in your system?
What's wrong with it?
--
Bye
This User Gave Thanks to Lem For This Post:
# 6  
Old 10-09-2012
thanks a lot for your kindness it works perfectly
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to select oldest folder in directory automatically and log process

The `bash` below uses the oldest folder in the specified directory and logs it. The goes though an analysis process and creates a log. My problem is that if there are 3 folders in the directory folder1,folder2,folder3, the bash is using folder2 for the analysis eventhough folder1 is the oldest... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

3. Shell Programming and Scripting

Delete log files automatically.

Here is the script I want to run to deleted log files after a certain time: touch /usr/WebSphere/AppServer/profiles/AppSrv01/apps/RSA/logs find /usr/WebSphere/AppServer/profiles/AppSrv01/apps/RSA/logs -atime +120 - exec rm -rf {}\; Exerytime I run it, it throws me the error: find: paths must... (2 Replies)
Discussion started by: lennyz04
2 Replies

4. Shell Programming and Scripting

check log for previous date

Hi, i want to check the log for previous date. For getting today's log I have written the script result=tot_max_`date+%y%m%d`.log Pls can anyone help on how to get for previous date. Thanks in Advance, Neha. (5 Replies)
Discussion started by: NehaKrish
5 Replies

5. Shell Programming and Scripting

Reading/Compressing of log file

Hello All Posted a similar thread in some other section too. Regrets if this section is not suitable for this post. Request all the members to be tolerant as i'm a newbie here :) Coming to the topic : I've this huge log files of size 20GB-30 GB in my unix server. I want to analyse the log... (2 Replies)
Discussion started by: sgbhat
2 Replies

6. UNIX for Dummies Questions & Answers

Compressing of log files

Hello All My first post in the forum. :) I've this huge log files of size 20GB-30 GB in my unix server. I want to analyse the log file for some error messages. But because of the enormity of the size of these files i'm not able to grep/search the pattern in the file . Also, tried to gzip the... (1 Reply)
Discussion started by: sgbhat
1 Replies

7. Shell Programming and Scripting

Automatically Rerun a script based on previous execution output

Hi Experts, I have a shell script called "updatevs" that is scheduled to run at 6.00 am everyday via cronjob. The cronjob will execute this script and output to a log file. The functionality of this script is to read the database and run a set of commands. This script is generally successful... (6 Replies)
Discussion started by: forumthreads
6 Replies

8. Shell Programming and Scripting

Script - How to automatically start another process when the previous process ends?

Hi all, I'm doing automation task for my team and I just started to learn unix scripting so please shed some light on how to do this: 1) I have 2 sets of datafiles - datafile A and B. These datafiles must be loaded subsequently and cannot be loaded concurrently. 2) So I loaded datafile A... (10 Replies)
Discussion started by: luna_soleil
10 Replies

9. Shell Programming and Scripting

Previous log and diff

Logs are created on a daily basis, the format of the log file is: servername_yymmdd. I need to check if there is a difference in the log created today with the previous one. I would appreciate help on how I can step back to the previous log and how can I test if there is a diff in the logs. ... (4 Replies)
Discussion started by: gugs
4 Replies

10. Shell Programming and Scripting

grep a log file to filter previous dates

Hi, I have problem of filtering a log file from my perl script. #cat /data/pinpe.csv_20070731 | nawk -v FS=, '{print $1','$18','$22','$26}' | grep -w 100 | grep -w 1 | nawk '{print $4}' Below is the output: 2009-06-16 2009-01-29 2009-06-02 2008-03-05 2007-08-05 2007-09-24... (5 Replies)
Discussion started by: pinpe
5 Replies
Login or Register to Ask a Question