Operating System - HP-UX
1837253 Members
2345 Online
110115 Solutions
New Discussion

Script gzip of oracle archive files

 
SOLVED
Go to solution
Robb Bailey
Occasional Advisor

Script gzip of oracle archive files

I would like to create a script that I can cron that will gzip oracle archive files. I have the steps that I need to do, but my scripting is not very good.

1) ls -t PROD*.arc >file1 List all .arc files to file1
2) vi file1
3) dd delete first file since I don't want to compress the most recent since it may be in the process of writing.
4)1,$s/PROD/\usr\/contrib\/bin\/gzip PROD/g
insert /usr/contrib/bin/gzip in front of PROD in file1

Would you be so kind as to give an example of the syntax of how to script this in a non-intractive mode?

Thank you,

Robb
5 REPLIES 5

Re: Script gzip of oracle archive files

ls -t PROD*.arc | sed ld | while read arcfile
do
/usr/contrib/bin/gzip ${arcfile}
done


HTH

duncan

I am an HPE Employee
Accept or Kudo
Solution

Re: Script gzip of oracle archive files

oops... should be:
ls -t PROD*.arc | sed 1d | while read arcfile
do
/usr/contrib/bin/gzip ${arcfile}
done


HTH

duncan


I am an HPE Employee
Accept or Kudo
Kofi ARTHIABAH
Honored Contributor

Re: Script gzip of oracle archive files

Robb:

You could do the following:

DAYSOLD=1
ARCHDIR=/path/to/your/archive/dir
cd $ARCHDIR
find . -name "PROD*.arc" -mtime +$DAYSOLD -exec gzip {} \;

or alternatively:

LEAVENEWEST=1 # the number of arc files to leave uncompressed
ARCHDIR=/path/to/your/archive/dir
cd $ARCHDIR
ls -t PROD*arc > /tmp/listoffiles
NOTARCHED=`cat /tmp/listoffiles | wc -l`
TOBEARCHED=`expr $NOTARCHED - $LEAVENEWEST`
for files in `tail -$TOBEARCHED /tmp/listoffiles`
do
gzip $files
done

good luck.
nothing wrong with me that a few lines of code cannot fix!
Robb Bailey
Occasional Advisor

Re: Script gzip of oracle archive files

Thanks for your help, the solutions are great!

Robb
Bill Perez
Occasional Advisor

Re: Script gzip of oracle archive files

I like to use the 'fuser' command to make sure that an archive log is not in use before I zip it thusly:

for arch_log in $arch_dest/*.log ; do
if [ -n "`fuser $arch_log 2>/dev/null`" ] ; then
continue
else
gzip $arch_log
fi
done

Unfortunately, on HP/UX (as opposed to AIX or Solaris), the 'fuser' command is a CPU hog and is therefore, by default, executable for root only. I just get my sysadmin to open it up so the oracle account can run it (and then just make sure your scripts use it judiciously).
If you can't say something nice, say something surreal.