09-13-2011
You can use something like this:
Code :
find <directory name> -name "*.log" -mtime +5 -exec rm {} \;
If you are using Oracle 11g or higher you may want to consider using
adrci. Here is a script that I wrote.
cat purge_adrci.ksh
===============
# Description:
# The following script provides to remove log and trace files generated in 11G.
#
# Notes:
#
# 1) That the purge time is in seconds but we prompt for days and convert
# to seconds (since that is how the adrci utilty works), to make things easier.
#
# 2) Second thing to take note of is that adrci works at the file level and if
# that file has been accessed in the number of minutes you specify in the purge
# command. Having said that, adrci will not remove sections of data from the
# alert log that meets the time criteria. Since the alert.log and the log.xml
# are typically updated quite frequently, they will probably not be removed.
GetOracleVersion()
{
if [ -n "$SCRIPT_PATH" ]
then
eval $SCRIPT_PATH
fi
oracle_version=`sqlplus -s / <<END
set pagesize 0 feedback off verify off heading off echo off;
select version FROM v\\$instance;
exit;
END`
echo "$oracle_version"
}
Check_DB_Version()
{
if [ -n "$SCRIPT_PATH" ]
then
eval $SCRIPT_PATH
fi
oracle_version=$(GetOracleVersion)
let support_UTSCDMP=0
if $(CompareVersions "$oracle_version" "<" "10.0")
then
return 1
else
if $(CompareVersions "$oracle_version" ">=" "11.2")
then
#
# 11g R2: new: -type UTSCDMP, for removing cdmp_* directories
#
let support_UTSCDMP=1
fi
fi
return 0
}
Convert_Days_To_Minutes()
{
if [ -n "$SCRIPT_PATH" ]
then
eval $SCRIPT_PATH
fi
if [ "$days" -lt 1 ]
then
echo "Number of days to purge must be specified" >> $ERR_FILE
return 1
else
if [[ "$days" = +([[:digit:]]) ]]
then
Minutes=`expr $days \* 1440`
else
echo "'$days' is not numeric value for days to purge" >> $ERR_FILE
return 1
fi
fi
return 0
}
GetAWK()
{
if [ -n "$SCRIPT_PATH" ]
then
eval $SCRIPT_PATH
fi
whence nawk > /dev/null
if [ $? -eq 0 ]
then
echo "nawk"
else
whence awk > /dev/null
if [ $? -eq 0 ]
then
echo "awk"
else
echo "gawk"
fi
fi
}
CompareVersions()
{
if [ -n "$SCRIPT_PATH" ]
then
eval $SCRIPT_PATH
fi
if [ $# -ne 3 ]
then
# incorrect number of arguments passed in.
return 1
fi
operand=$2
# First we compare the two numbers.
# This will give us a return status of 255, 0 or 1.
# 255 means arg1 < arg2
# 0 means arg1 = arg2
# 1 means arg1 > arg2
VersionNumCompare $1 $3
return_status=$?
if [ ${return_status} -eq 0 ]
then
# This means that the both versions are equal to each other.
# we now need to check if the caller wants the arguments to be
# equal or not.
if [ "$operand" = "=" ] || [ "$operand" = "==" ] ||
[ "$operand" = ">=" ] || [ "$operand" = "<=" ]
then
return 0
else
return 1
fi
elif [ ${return_status} -eq 1 ]
then
# This means that the first version is greater than the
# second version, so we now check if that is what the caller
# wanted.
if [ "$operand" = ">" ] || [ "$operand" = ">=" ]
then
return 0
else
return 1
fi
else # return_status is 255
# If we got here, the first version is lower than the second
# version, so we check if the caller wanted it to be so.
if [ "$operand" = "<" ] || [ "$operand" = "<=" ]
then
return 0
else
return 1
fi
fi
}
#
# This function compares two Versions.
#
# Arguments:
# 1: Version with dots "." separating the subversions.
# Example: "1.2.3.4" or "00001.0002.03.4"
# 2: Same as the argument 1.
#
# Returns:
# 0: If the versions are equivalent.
# 1: If the second version is lower.
# 255: If the first version is lower.
#
VersionNumCompare()
{
if [ -n "$SCRIPT_PATH" ]
then
eval $SCRIPT_PATH
fi
if [ $# -ne 2 ]
then
# incorrect number of arguments passed in.
return 255
fi
AWK=$(GetAWK)
echo $* | $AWK ' {
version1n=split($1, version1, ".");
version2n=split($2, version2, ".");
if ( version1n > version2n )
commonParts=version2n;
else
commonParts=version1n;
i=1;
while ( i <= commonParts )
{
if ( version1[i] < version2[i] )
exit 255;
else if (version1[i] > version2[i] )
exit 1;
i=i+1;
}
# so far everything is equal.
while ( i <= version1n )
{
if ( version1[i] != 0 )
exit 1;
i=i+1;
}
while ( i <= version2n )
{
if ( version2[i] != 0 )
exit 255;
i=i+1;
}
# everything is equal
exit 0
} '
}
purge_ardci()
{
timestamp=`date +"%Y-%m-%d %H:%M:%S"`
echo "adrci purge started at $timestamp"
# Purge ADR contents
adrci exec="show homes"|grep -v : | while read file_line
do
echo "adrci purging diagnostic destination " $file_line
echo "purging ALERT older than $days days ..."
adrci exec="set homepath $file_line;purge -age $Minutes -type ALERT"
echo "purging INCIDENT older than $days days ..."
adrci exec="set homepath $file_line;purge -age $Minutes -type INCIDENT"
echo "purging TRACE older than $days days ..."
adrci exec="set homepath $file_line;purge -age $Minutes -type TRACE"
echo "purging CDUMP older than $days days ..."
adrci exec="set homepath $file_line;purge -age $Minutes -type CDUMP"
echo "purging HM older than $days days ..."
adrci exec="set homepath $file_line;purge -age $Minutes -type HM"
if [ $support_UTSCDMP -eq 1 ]
then
echo "purging UTSCDMP older than $days days ..."
adrci exec="set homepath $file_line;purge -age $Minutes -type UTSCDMP"
fi
echo "\n"
done
timestamp=`date +"%Y-%m-%d %H:%M:%S"`
echo "adrci purge completed at $timestamp"
}
let days=0
let Minutes=0
# Examine options
while getopts d:s: OPTS; do
case "$OPTS" in
d) days=$OPTARG;;
s) ORACLE_SID=$OPTARG;;
*) usage
return 2;; # Invalid args
esac
done
shift `expr $OPTIND - 1` # remove argument(s)
Convert_Days_To_Minutes
if [ $? -ne 0 ]
then
return 1
fi
Check_DB_Version
if [ $? -ne 0 ]
then
echo "ardci not supported for release "$oracle_version" " >> $ERR_FILE
return 1
fi
purge_ardci
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi all,
i would like to write the shell script to remove the out-dated log
my log file name will be like this:
access_20050101.log
access_20050102.log
.
.
.
access_20071007.log
access_20071008.log
access_20071009.log
i has try to write the command as following, it will be remove the... (2 Replies)
Discussion started by: eric_wong_ch
2 Replies
2. Shell Programming and Scripting
currently i am doing a project where in i am creating files everyday with a name xyz_date for e.g. xyz_20071010,xyz_20071011 ... in this fashion.so at a particular point of time i need only 31 days of data.suppose we are executing the code today then we will have only 31 days data present and... (7 Replies)
Discussion started by: dr46014
7 Replies
3. UNIX for Advanced & Expert Users
My code is
tar -cvf logs.tar `find /usr/openv/logs/512*.log -mtime +2` && find *.log* -mtime +2 -exec rm {} \;
this gives me output as:
tar: Missing filenames:confused: (1 Reply)
Discussion started by: timus1980
1 Replies
4. Solaris
Hi
I Need To Remove Logs Older Than April 1 St(4/1/2007) By Date
I Have A Script To Remove 3 Months Old Like Using 90 Days
Thanks (3 Replies)
Discussion started by: cvdev
3 Replies
5. UNIX for Dummies Questions & Answers
Hi
Can u please tell me how to delete last 10 days logs .. (9 Replies)
Discussion started by: pb18798
9 Replies
6. Shell Programming and Scripting
I want to write a shell script that deletes all log files in a directory that are older than 30 days except for 3 files:
I am using the following command:
find /tmp/logs -name "*.log" -mtime +30 -exec rm -f {} \;But this command deletes all the log files.
How can i modify this script that... (5 Replies)
Discussion started by: mmunir
5 Replies
7. Shell Programming and Scripting
Hi All,
I have a requirement to fetch logs of last 'N' days.
I am trying the following command which is working fine if it finds the date of that day in logfile.
START=`TZ="GMT+$((24*N))" date +"%Y %b %d"`
this is being used to fetch 'N'th day's date
and
awk '/'"$START"'/{p=1}... (24 Replies)
Discussion started by: KDMishra
24 Replies
8. Shell Programming and Scripting
i am using HP-UX OS......
delete logs older than 60 days
find -mtime +60 | grep -i '.*log' | xargs rm
-mtime is nt available in HP-UX, pls tell me other option ? (2 Replies)
Discussion started by: only4satish
2 Replies
9. Shell Programming and Scripting
Hi All,
I am new to the scripting and using solaris 10 OS. Please suggest me from the below script which modifications need to be done to delete the files more that 2days older. Current script is deleting existing file.
# Remove old explorer runs if needed
DIR=`dirname ${EXP_TARGET}`
if ... (2 Replies)
Discussion started by: Navkreddy
2 Replies
10. Shell Programming and Scripting
As i am working in unix environment so i have an logs that is created by my application at the following location that is
/opt/app/glac/current/servers/ops/logs
inside the logs directory there are different kinds of logs(that is the file having extension as .log ) have been created... (1 Reply)
Discussion started by: 2015nks
1 Replies