Script for reducing logs


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script for reducing logs
# 1  
Old 11-09-2001
Script for reducing logs

Hi, I'm not good in scripting, maybe someone can help me.
I need to delete the lines that contains the last month date from a text file. Each line has the following date format:
[08/Nov/2001:17:06:58 +0300]

So the script should check the actual month, and delete all the lines that contains the past month. The script runs once a month, of course.

As you can see, I know what I need but I don't know how to do it.

If you know how to do it, please, enlight me with you knowledge....

ThanksSmilie
# 2  
Old 11-09-2001
Hi,

This is fairly easy to accomplish.

You could use grep.

First copy your logfile to a *.old filename.
$ cp logfile logfile.old

Then grep -v to get rid of undesirable lines containing the pattern you want to delete.
$ cat logfile.old |grep -v "Nov/2001" > logfile

OR

Better, you can just save your logs to *.old1, *.old2 when the first day of the month arrives, run from cron.

# minutes (0-59) hours (0-23) dates (1-31) months (1-12) days (0-6)
0 0 1 * * /some/log/cleahup.sh

$ vi cleanup.sh

cp /some/log/file1 /some/log/file2
cp /some/log/file /some/log/file1
> /some/log/file

Smilie
# 3  
Old 11-09-2001
OK I will use the second option. It was more simple than I thought, thank you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Reducing / on rootvg

The root filesystem was mirrored, someone/something stopped mirroring, and increased / and /home to ridiculous values (/ got increased to 102gb and its only using 4.3gb, so 98gb is free). Can I reduce the / (/dev/hd4) filesytem down WITHOUT corrupting the the OS? I would do a: chfs -a size=10g... (6 Replies)
Discussion started by: mrmurdock
6 Replies

2. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

3. Red Hat

Profile.d script logs out

Hi, I included a command set -o vi & sudo -l user -c script in profile.d and /etc/profile. unfortunately the script has some command that logs me out every time I try to login from all users including root user. this is happening from GUI. can I login to prompt directly? or is there an... (7 Replies)
Discussion started by: ahmedwaseem2000
7 Replies

4. Shell Programming and Scripting

[Help] Script to monitor logs

Hello friends, as they are? First of all sorry for my poor English. I tell them what is my problem. I have the following script, which is basically what makes error search for a pattern within a folder containing logs. The script works fine, the problem is that whenever I find a pattern of new... (2 Replies)
Discussion started by: romanrsr
2 Replies

5. UNIX for Dummies Questions & Answers

Need script to rotate logs

I have few solaris-10 non global zones, where one application is writing some logs to /var/ovd/ConfigLogs. It keeps increasing all the time, as it is needed by application team as of now. I want a small script, which I can configure in cronjob, which should : - Run every Saturday 10 PM - Copy... (5 Replies)
Discussion started by: solaris_1977
5 Replies

6. Shell Programming and Scripting

Script for monitoring logs

hi, i'm using unix solaris 5.8. I have to write a shell script for monitoring logs. whenever the logs are not updated more than one hour an alert will be send to my mail. I'm new to Unix, so could anyone help me to find this. (3 Replies)
Discussion started by: Arasu
3 Replies

7. Shell Programming and Scripting

Script to check logs

I have 5 log files under different directores . say for eg abc under /home/dir1 , xyz under home/dir2 . is there a script that i can run from say /home that searchers all these files for string or combination of strings and write to a file eg search file by timestamp|keyword o/p in a file (6 Replies)
Discussion started by: Nevergivup
6 Replies

8. Shell Programming and Scripting

script for reading logs of a script running on other UNIX server

Hi, I have a script, running on some outside firwall server and it's log of success or failure is maintained in a file. I want to write a script which ftp that server and reads that file and checks the logs and if failure , I will send mail notification. Please let meknow if I am not... (1 Reply)
Discussion started by: vandana.parwani
1 Replies

9. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

10. Shell Programming and Scripting

script to move logs

Does anyone have a good script to move log files from a cron? There are a lot of logs, about 100 or more and they are constantly being written too. (7 Replies)
Discussion started by: photon
7 Replies
Login or Register to Ask a Question