Sunday, February 8, 2015

Useful Scripts

Following script is used to clean up the logs by executing the script with 2 parameters (domain name & server name)

cleanLogs.sh

#!/bin/ksh

usage()
{
 echo "\n!!!!!Usage!!!!!!!"
 echo
 echo " cleanLogs.sh "
 echo "\ne.g. cleanLogs.sh mydomain myServer"
 echo
}
if [ $# -ne 2 ]
then
 usage
 exit 2
fi

domain=$1
server=$2
FMW_HOME=/opt/fmw/

#Remove the logs older than 30 days
find $FMW_HOME/user_projects/domains/${domain}/servers/${server}/logs/*_log.* -mtime +30 | xargs rm

#Compress the logs older than 15 days
find $FMW_HOME/user_projects/domains/${domain}/servers/${server}/logs/*access_log.* -mtime +15 | xargs compress

exit




Following script can be used to put in scheduled jobs for cleaning up the logs without any parameters

cleanAllServerLogs.sh

#!/bin/ksh

FMW_HOME=/opt/fmw/

##AdminServer Logs clean-up

#Remove Admin Server logs older than 30 days
find $FMW_HOME/user_projects/domains/myDomain/servers/AdminServer/logs/*_log.* -mtime +30 | xargs rm

#Compress Admin Server logs older than 15 days
find $FMW_HOME/user_projects/domains/myDomain/servers/AdminServer/logs/*access_log.* -mtime +15 | xargs compress

##ManagedServer Logs clean-up

for i in 1 2 3
do
#Remove MS logs older than 30 days
find $FMW_HOME/user_projects/domains/myDomain/servers/myServer_${i}/logs/*_log.* -mtime +30 | xargs rm

#Compress MS logs older than 15 days
find $FMW_HOME/user_projects/domains/myDomain/servers/myServer_${i}/logs/*access_log.* -mtime +15 | xargs compress
done


exit

No comments:

Post a Comment