Select Page

Use Autoconfig for common system administrator tasks

Author: Chuck Edwards | | December 11, 2009

Use Autoconfig for common system administrator tasks

Autoconfig is a wonderful tool that may be extended and customized to meet a variety of needs.  One mundane task I don’t deal with anymore is scripting certain basic operating system scripts.  For example:

  • Rotating logs
  • Cleaning out old trace files
  • Init scripts

… are all examples of cron jobs and scripts that must be created post-install.  Many DBAs have a set of scripts they use and modify, but why not use an autoconfig template to generate what you need every time

I’ll use an init script as an example.  Oracle provides adstrtal.sh and adstpall.sh for starting and stopping an apps environment; however neither of those scripts are ready to run out of /etc/init.d for system startup and shutdown.

Below is an Autoconfig template that will generate an init.d script that will call both adstrtal.sh and adstpall.sh on system startup and shutdown, respectively.  The script is designed for a RedHat Linux variant like RHEL, OEL, or CentOS.  The application version was 12.1.1.

#!/bin/bash

# %s_dbSid% Start script for the vis applications
#
# chkconfig: - 85 15
# description: %s_dbSid% is an oracle applications instance

# Must be root
[ $USER != "root" ] && echo "User must be root" && exit 1

# source functions
. /etc/rc.d/init.d/functions

prog=app%s_dbSid%
appstop=%s_config_home%/admin/scripts/adstpall.sh
appstart=%s_config_home%/admin/scripts/adstrtal.sh
mgrctl=%s_config_home%/admin/scripts/adcmctl.sh
appuser=%s_appsuser%
appgroup=%s_appsgroup%
appssys=%s_apps_user%
logdir=/var/log/oa
logfile=app%s_dbSid%

LOG=$logdir/$logfile
USAGE="$prog: [start|stop|abort]"
RETVAL=0

if [ $# -lt 1 ]; then
echo $USAGE
exit 1
fi

if [ ! -d $logdir ]; then
mkdir -p $logdir
touch $LOG
chgrp -R $appgroup $logdir
chmod g+r $logdir
fi

# Define some functions

exit_error() {
RETVAL=$1
message="$2"
echo "$message"
echo_failure
echo
exit $RETVAL
}

get_appspass() {
# Substitute a better password retrieval function
SECRET=/home/$appuser/.secret
appspass=`grep ^%s_apps_user%= $SECRET | awk -F"=" '{print $2}'` 2>>$LOG
[ $? -ne 0 ] && echo "Could not find %s_apps_user% password - exiting" >>$LOG 2>&1 && exit 1
CONNECT="%s_apps_user%/$appspass"
}

# Start the applications
start() {
echo -n $"Starting $prog: "
get_appspass
su - $appuser -c "$appstart $CONNECT" >>$LOG 2>&1
RETVAL=$?
return $RETVAL
}

# Stop the applications
stop() {
echo -n $"Stopping $prog: "
get_appspass
su - $appuser -c "$appstop $CONNECT" >>$LOG 2>&1
RETVAL=$?
return $RETVAL
}

# Stop the applications and abort the concurrent managers (faster)
abort() {
echo -n $"Aborting $prog: "
get_appspass
su - $appuser -c "$mgrctl abort $CONNECT" #| tee >>$LOG 2>&1
su - $appuser -c "$appstop $CONNECT" #| tee >>$LOG 2>&1
RETVAL=$?
return $RETVAL
}

# Main program

mode=$1

case $mode in
start)
start
;;
stop)
stop
;;
abort)
abort
;;
*)
echo $USAGE
exit 1
esac

if [ $RETVAL -eq 0 ]; then
echo_success
else
echo_failure
fi
echo

exit $RETVAL

To install this script, all I need to do is the following:

Place the script in a template file in my custom application top.

Create a driver that will create the script; I usually create a /tools directory for this sort of thing.

Run autoconfig to create the script.

As root, copy the script to /etc/init.d

Use chkconfig to enable auto start/stop on system boot:


$ chkconfig –-add
$ chkconfig on

That’s it!  Now every time I create a clone, I have a new init script for that node.  If a path or other dependent context value changes, I simply copy the updated script into /etc/init.d and follow the steps above.

I should note that with this script specifically, because it requires the apps password, you should probably find a better way to store and retrieve the apps password.  In this example, I put it in a file called /home/appl/.secret, which had permission bits set to 660.  That’s an “OK” solution, but not great.  The script grabs the password using a function specifically to allow minimal fuss and muss when updating the password storage and retrieval method.

Anyway, it’s pretty easy to see how one could leverage Autoconfig to create simple time-saving scripts because Autoconfig already “knows” where everything is.

Here’s an example of a script to clean up concurrent manager log and output:


#!/bin/sh

env_file="%s_applfenv%"

if [ ! -f $env_file ];
then
printf "Cannot find environment file $env_filen"
printf "ERRORCODE = 1 ERRORCODE_ENDn"
exit 1
else
. $env_file
fi

# Clean up concurrent manager log and output directories
/usr/bin/find $APPLCSF/$APPLOUT -name "*.out" -ctime
+%c_conc_out_ret% | xargs rm -rf
/usr/bin/find $APPLCSF/$APPLLOG -name "*.req" -ctime
+%c_conc_log_ret% | xargs rm -rf

# Clean up the instance logs
/usr/bin/find $INST_TOP/admin/log -type d -ctime
+%c_inst_log_ret% | xargs rm –rf;

exit $?

In this example, I created 3 custom context variables:

c_conc_out_ret
c_conc_log_ret
c_inst_log_ret

Each are set to the retention period in days for their respective logs.

Installation for a script like this is even more hands-off than an init script.  Typically log cleanup scripts are called from cron and are often registered as individual crontab commands.  For this script, a single crontab entry could point to the absolute location of the script.  If the value of an environment or context variable changed at any time, running Autoconfig would automatically update the scheduled job.

Operating system maintenance plays a critical role in a well-organized, automated Apps environment; the less manual scripting there is, the less likely it is to be skipped.

How to Solve the Oracle Error ORA-12154: TNS:could not resolve the connect identifier specified

The “ORA-12154: TNS Oracle error message is very common for database administrators. Learn how to diagnose & resolve this common issue here today.

Vijay Muthu | February 4, 2021

Data Types: The Importance of Choosing the Correct Data Type

Most DBAs have struggled with the pros and cons of choosing one data type over another. This blog post discusses different situations.

Craig Mullins | October 11, 2017

How to Recover a Table from an Oracle 12c RMAN Backup

Our database experts explain how to recover and restore a table from an Oracle 12c RMAN Backup with this step-by-step blog. Read more.

Megan Elphingstone | February 2, 2017

Subscribe to Our Blog

Never miss a post! Stay up to date with the latest database, application and analytics tips and news. Delivered in a handy bi-weekly update straight to your inbox. You can unsubscribe at any time.

Work with Us

Let’s have a conversation about what you need to succeed and how we can help get you there.

CONTACT US

Work for Us

Where do you want to take your career? Explore exciting opportunities to join our team.

EXPLORE JOBS