1827286 Members
2550 Online
109717 Solutions
New Discussion

Re: script help!!

 
SOLVED
Go to solution
mw_9
Occasional Advisor

script help!!

Deleting from end of line to designated line
can you help me?
after backup 'oracle archive log file' then,
except do not backed up file,delete backed up file
.....

afiedt.buf
arch_0000026778.arc
arch_0000026779.arc
arch_0000026780.arc
arch_0000026781.arc
arch_0000026782.arc
arch_0000026783.arc
arch_0000026784.arc
....

How can I delete from last line(arch_0000026784.arc) to previous 2 or 3 line(arch_0000026782.arc,arch_0000026783.arc)
add up
5 REPLIES 5
twang
Honored Contributor
Solution

Re: script help!!

You want to remove oracle archived logs from system. I would recommend that you remove those archived logs older than a certain date/time. You can do it via a cronjob.
To do so you can using the touch command to create a file at the moment of time you wish to use as cutoff, see follows:

Script content is as follows:
-------------
touch -t 200308201230 temp

find /arch_dir ! -newer /arch_dir/temp -exec rm {} \;
-------------
This will create temp file and set it's time to Aug 20 12:30 PM, then remove those files NOT newer than the time stamp on temp. Of course you can control this time (using date)to determine the files which you want to remove.
Hope this helps.

Brian Markus
Valued Contributor

Re: script help!!

I was bored, so I started the script for you. :) Make a file with all your entries (arch_0000026778.arc etc???) then use the script to run through the file, and based on a count you can then do anything you want. With a little more code, you could tell it to do something from line 7 - 10, or from line 10 on.

Hope this helps!


-Brian.


#!/bin/sh
myfile=test.txt
count=`wc -l $myfile | awk '{ print $1 }'`
cnt=0
for lines in `cat $myfile`
do
if [ $cnt -eq $count ]
then
echo $lines
else
cnt=`expr $cnt + 1`
echo $cnt
fi
done
When a sys-admin say's maybe, they don't mean 'yes'!
Leif Halvarsson_2
Honored Contributor

Re: script help!!

Hi,
To remove the tree oldest files:
rm `ls -t *.arc |tail -3`
Massimo Bianchi
Honored Contributor

Re: script help!!

How do you backup the archive?
best way, if you use rman, would be to use

"archivelog all delete input;"

in the rman script.

Else, Leif's solution may be the best....

Massimo

mw_9
Occasional Advisor

Re: script help!!

thank you for all your help
add up