Solved

shell script

Posted on 2015-02-05
9
167 Views
Last Modified: 2015-06-23
I need help with shell script to clean up archivelog every 1 hour  

on unix solaris

rman  target /

delete archivelog all;
crosscheck archivelog all;
0
Comment
Question by:k khnn
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Accepted Solution

by:
Smita Melinmani earned 100 total points
Comment Utility
I have not tested the script though. It would look like below:

#!/bin/sh
echo "####################################################" >/home/user/archivelogdelete.log
echo "Deleting the archivelogs at `date`"  >>/home/user/performance.log
echo "####################################################" >> /home/user/archivelogdelete.log
echo  "" /home/user/archivelogdelete.log

rman target=/ << EOF
RUN {
  delete archivelog all;
  crosscheck archivelog all;
}
EXIT;
EOF
echo "END ..." >/home/user/archivelogdelete.log

And you can schedule this job in cron every hour as below :

0 * * * * your_script_name
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 200 total points
Comment Utility
>>clean up archivelog every 1 hour  

You are backing up the archived redo to tape before deleting them, right? If not, why are you in archive redo mode if you don't care about recovery?

My RMAN is a little rusty but I don't think you need to crossheck after a delete.  You normally do a crosscheck before a delete in case the files have been removed outside of RMAN.  The crosscheck tells RMAN to make sure what it thinks is on disk, actually is.

The above cron and script needs a little more:  The Oracle environment.  shell scripts executed from cron don't have the environment set up.

If everything is set up properly the additions below should work but I'm not on Unix where I can actually test them.

You'll need to change the ORACLE_SID and possibly the path to oraenv.

I also didn't change to order of delete and crosscheck.  I don't believe it is correct but cannot test.
#!/bin/sh
echo "####################################################" >/home/user/archivelogdelete.log
echo "Deleting the archivelogs at `date`"  >>/home/user/performance.log
echo "####################################################" >> /home/user/archivelogdelete.log
echo  "" /home/user/archivelogdelete.log

ORAENV_ASK=NO
export ORACLE_SID=ORCL
. /usr/local/bin/oraenv
rman target=/ << EOF
RUN {
  delete archivelog all;
  crosscheck archivelog all;
}
EXIT;
EOF
echo "END ..." >/home/user/archivelogdelete.log

Open in new window

0
 

Author Comment

by:k khnn
Comment Utility
i am getting

ORACLE_SID= mydbsid   is not an identifier
0
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 200 total points
Comment Utility
It depends on what shell /bin/sh really is.  It may not like the combined export command.

Change this:

export ORACLE_SID=ORCL

to this:

ORACLE_SID=ORCL
export ORACLE_SID
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:k khnn
Comment Utility
When i manually delete archivelog it asks

do you really want o delete the above objects (enter yes or no)? Yes

how do add this in this shell?
0
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 200 total points
Comment Utility
Change your command from DELETE to DELETE NOPROMPT

There are ways to do it with the shell script, but removing the prompt at the source is probably easier.
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 200 total points
Comment Utility
>>ORACLE_SID= mydbsid   is not an identifier

There was also a space in there.
0
 
LVL 22

Expert Comment

by:Steve Wales
Comment Utility
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now