help in sed script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help in sed script
# 1  
Old 07-03-2003
help in sed script

I am having a shell script that connects to database half hourly and pulls out the backlog from some tables. Now that logfile is growing too big and I need to housekeep it! effectively I want to keep last 30 days data in that file and move rest to archived file.
The file contents are as below.
the algorithm I want is as follow :

take input file my.log
go to first line, check if this is more than 90 days
if it is then
pick those lines fom log file till the next sql plus ( i.e. that block) and append to some archive file ( difficult ?)
delete these lines from current file

if it is not then leave it as it is

can somebody help me writting this please ?

---------------------------------------------------------------------------------SQL*Plus: Release 8.1.7.0.0 - Production on Thu Feb 27 19:20:00 2003

(c) Copyright 2000 Oracle Corporation. All rights reserved.

Enter user-name:
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

SQL> SQL> 76834445

SQL> 76834445

SQL> 2 3 4 5 6 7 8 9 ELFORDE
75241084 1593361 25-NOV-02 18:18:10

HEWITTSA
76238384 596061 20-DEC-02 09:18:09
SQL> Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Pro
duction
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

SQL*Plus: Release 8.1.7.0.0 - Production on Thu Feb 27 19:50:00 2003

(c) Copyright 2000 Oracle Corporation. All rights reserved.

Enter user-name:
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production
---------------------------------------------------------------------------------

Thanks in advance.
# 2  
Old 07-03-2003
Re: help in sed script

I think I'm following you.. it would help if you could post a portion of the log file to look at.
# 3  
Old 07-04-2003
herer it is again !
***************************************************

SQL*Plus: Release 8.1.7.0.0 - Production on Thu Feb 27 19:20:00 2003

(c) Copyright 2000 Oracle Corporation. All rights reserved.

Enter user-name:
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

SQL> SQL> 76834445

SQL> 76834445

SQL> 2 3 4 5 6 7 8 9 ELFORDE
75241084 1593361 25-NOV-02 18:18:10

HEWITTSA
76238384 596061 20-DEC-02 09:18:09

SQL> Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Pro
duction
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

SQL*Plus: Release 8.1.7.0.0 - Production on Thu Feb 27 19:50:00 2003

(c) Copyright 2000 Oracle Corporation. All rights reserved.

Enter user-name:
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

SQL> SQL> 76834451

SQL> 76834451

SQL> 2 3 4 5 6 7 8 9 ELFORDE
75241084 1593367 25-NOV-02 18:18:10

HEWITTSA
76238384 596067 20-DEC-02 09:18:09


SQL> Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Pro
duction
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

SQL*Plus: Release 8.1.7.0.0 - Production on Thu Feb 27 20:20:01 2003

(c) Copyright 2000 Oracle Corporation. All rights reserved.
Enter user-name:
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

SQL> SQL> 76834459

SQL> 76834459

SQL> 2 3 4 5 6 7 8 9 ELFORDE
75241084 1593375 25-NOV-02 18:18:10

HEWITTSA
76238384 596075 20-DEC-02 09:18:09


SQL> Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production
***************************************************

This process runs for every half an hour!

THanks in advance.
# 4  
Old 07-04-2003
Okay, but most of the time a log is the same set of information written to a file, such as

06 30 2003 Data Data Data
07 01 2003 Data Data Data
07 02 2003 Data Data Data

What you've posted looks more like screen output.. the version of SQL you're using.. the SQL> prompt..

If that is what's being written to your log, how do you know what day that entry is for? Because you need to know that day in order to determine how old the entry is and delete it from the log..

Are you saying that the entry you included here is from Thu Feb 27 19:20:00 2003 ?
# 5  
Old 07-04-2003
Yeah, the log contains the router log information and helps us keeping watch on how much the lag is! So it may be repeating information in case routers are not working! ( and In that case we need to make them work )

I have posted the part of spool file of what's happening.

When the file will be run ( it runs every half an hour!), we will know what date it is , we can spool out the date! and then calculate the 90 days before that day, and remove the block of lines from that date! ( i.r. I need to maintain the information only for last 90 days and not before that !) .

Now what I need is that once I have the 90_days_before date how to delete all lines before that line ?

am I elaborate enough ?
# 6  
Old 07-04-2003
I'm just curious to know why you don't write the log to a new file everyday....say ccyymmddhhss.log format. If you're already writing a script to pull the data from the database, I assume with a here statement that connects and unload your data, you can easily create this datetime variable to use as your log filename....then all you have to do is do a find exec rm against any files over 90 days...
Of course, this assumes you don't need to keep appending to the log file...

Just wondering...
# 7  
Old 07-04-2003
Yeah, That sure would have been an easy win, If I was allowed to do that , BUt I am supposed to keep it in single file only!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed script help

I am having a file as stated below : File 1: ########################## idnd a integer 2; list 1 ; list2 ; chip top alist( .a(1) , .b(2) , .c(3) , .d(1) , .e(7) , .n(80), .d(1) , .g(7) , .n(80), .f(1) , .e(7) , .m(80)); lis 7 nfj ; jdjd kn; jsjd l ; (4 Replies)
Discussion started by: kshitij
4 Replies

2. Shell Programming and Scripting

SED script

Hi , i am stuck in this simple script. #!/bin/ksh echo "enter the file name" read flname echo "enter version" read ver grep $flname /home/con/snsc/perl/map > flplist dirname `cat flplist` | sed 's/\/so${vers}\//\/so${vers}_xyz\//' > dirlist the map file is basically a list of file... (3 Replies)
Discussion started by: debu182
3 Replies

3. Shell Programming and Scripting

sed script

I am beginner for Unix. I practicing unix shell script. I worked out some sed script example from internet. Everything fine. But in real unix environment, where sed script is mainly used.? Can anyone give some examples for the usage of sed script in real unix environment. It will be useful for... (1 Reply)
Discussion started by: gwgreen1
1 Replies

4. Homework & Coursework Questions

Sed script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Create a sed script that will display a list of all users in the /etc/passwd file that belong to the group... (0 Replies)
Discussion started by: lakers34kb
0 Replies

5. Shell Programming and Scripting

sed in script

I'm trying to write a simple script that replaces a string. The script works for uninterrupted strings, but as soon as sed encounters a space it stops reading the new string. I've tried double quotations in sed and backslashes before the $, however these don't work. Below is the script. Any help... (9 Replies)
Discussion started by: dsell002
9 Replies

6. UNIX for Dummies Questions & Answers

sed script

:rolleyes: I have a series of folders /temp/a /temp/b /temp/c In folders a, b, and c, I have files a1.txt..........a20.txt b1.txt..........b40.txt & c1.txt..........c60.txt Each file has the same data format :- Line... (2 Replies)
Discussion started by: grinder182533
2 Replies

7. Shell Programming and Scripting

sed script

how to convert the follow sed script file into a command line ? example: /^\.TS/,/^\.TE/{ /^$/p } I have tried the below but it is not working: # sed -n "/^\.TS/,/^\.TE/{/^$/p}" file file: 111 .TS 222 $333 << extract this line 444 .TE 555 (2 Replies)
Discussion started by: 3Gmobile
2 Replies

8. Shell Programming and Scripting

sed in a script

I am trying to run a sed command within a script to edit a file. I am trying to put the value of MYUSER into the sshd_config file. Instead of putting the value of the variable, MYUSER, it puts in the string ${MYUSER}. Anyone know a good solution to this? cat ${SSHD_CONFIG} | sed... (1 Reply)
Discussion started by: Mike_the_Man
1 Replies

9. Shell Programming and Scripting

Sed script

/\/\*/!b :x /\*\//!{ N bx } s/\/\*.*\*\/// This scipt should remove c like commnets /**/ i know what de last line does but i dont't know what the first lines do Can anyone explain please (3 Replies)
Discussion started by: clauchiorean
3 Replies

10. Shell Programming and Scripting

Sed script maybe?

I have a lot of script files that were created by Extract in a dir that no longer exists. Now that I have to run these scripts they 'all' have to be changed. I'm looking for a way to do a 'mass' change if possible. So far, I've dumped all of the script file names to a file and sorted them to... (5 Replies)
Discussion started by: HOlli
5 Replies
Login or Register to Ask a Question