Database Reference
In-Depth Information
Evidence of Life
Every shell script you develop should be executable at the command line for testing one-off runs, and should also
be executable through a scheduler like Cron without any modification. Resist the temptation to use two versions of
the same script to enable both modes of operation. This can turn into a maintenance nightmare as the complexity of
your environment grows. Instead, test for a live user session by looking at the nature of the session that is calling the
script. At run-time, a file system entry for each terminal session will be made in the /dev directory for each live user
connection. TTY is an old term for T ele t ype Session—your terminal session. Cronned executions aren't called from a
terminal, of course, so there is no /dev/tty associated with those executions.
Test for the existence of a TTY session with an if statement and set your runtime variables accordingly. For
instance, if your script requires that the database name be passed on the command line, you will respond to missing
inputs differently for an attended session than you would for a cronned/scheduled session:
if [ ${1} -eq 0 ]; then
if tty -s ; then
read -p "Please provide the name of the database: " thisSID
else
echo "The database name was not provided on the command line" >>runtime.log
exit
fi
fi
This type of session checking was removed from the example scripts for clarity.
Sample Function Library
This function library is sourced by many of the shell scripts found in the remainder of this section. It can also be
sourced for immediate use in a terminal session, or sourced for use in any other shell script.
Sample Script: emcli_functions.lib
#!/bin/sh
#/* vim: set filetype=sh : */
# ==============================================================================
# File: emcli_functions.lib
# Purpose: Shell script functions for common emcli tasks
# File permission: This file is sourced and never executed
# Echo statements: Formatting for echoed statements has been removed for this
# scripting sample to keep the logic clear. Be kind to your
# users and add white space liberally in your own copy
# ==============================================================================
# The SysmanPassword variable is used in a single place to call your proprietary
# password encryption solution, or in a single location to record the SYSMAN
# password for use in your scripts and within the functions in this library.
# It is strongly recommended that you implement a more secure solution such as encryption/decryption
# through Java or another tool
# ------------------------------------------------------------------------------
SysmanPassword=Sup3r_S3cr3t_PASSWORD
 
Search WWH ::




Custom Search