Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Shell Script Heros

Re: Shell Script Heros

From: <fitzjarrell_at_cox.net>
Date: 7 Nov 2006 13:39:23 -0800
Message-ID: <1162935563.176809.15880@i42g2000cwa.googlegroups.com>

oracledba.amit_at_gmail.com wrote:

> Dear Sirs,
>
> I am new to shell scripting and I have to create a shell script that
> will ask the user to enter DB Sid, User Name and Password. The script
> will then validate this information.
>
> If the user input is not valid, then he should be shown a message that
> user input was not right. And if the user-input is right, then I have
> to run few scripts, after showing him a messege that his input was
> right.
>
> Any clues on how to do that would be a good help.
>
> Thanking you in anticipation.
>
> Regards,
> Amit

#!/bin/ksh
#
# script_examp.ksh
#
# Example script to illustrate collecting, validating
# and using Oracle connection information
#

#
# Set the user profile
#

. ~/.profile

#
# Set USAGE statement, tnsnames.ora location and
# sqlplus location
#

USAGE="`basename $0` -s ORACLE_SID -u USERID -p USERPASS" TNSNAMES="$ORACLE_HOME/network/admin/tnsnames.ora" SQLPLUS=`which sqlplus`

#
# Log file for output
#

LOG=script.log

#
# Collect arguments passed to script
#

while getopts s:u:p: arg
do

        case $arg in
        s) OSID=$OPTARG;;
        u) UID=$OPTARG;;
        p) UPASS=$OPTARG;;
        \?) echo $USAGE
           exit 1;;
        esac

done

shift `expr $OPTIND - 1`

#
# Check validity of OSID value
#

grep $OSID $TNSNAMES >> /dev/null

status=$?

#
# Did not find this in the local tnsnames.ora file
#
# Notify user and exit
#

if [ $status -eq 1 ]
then

        echo "$OSID is not a valid Oracle SID"
        exit 2

fi

#
# Notify user of impending connection
#

echo "Connecting to $OSID as $UID using password $UPASS"

#
# Attempt to connect to Oracle
#
# Exit with a status of 51 if the connection
# attempt generates an error
#
#
# If connection is good continue by running
# scripts
#
# Do not exit if scripts generate errors
#

$SQLPLUS -s /nolog << EOF > $LOG 2>&1
whenever sqlerror exit 51
connect $UID/$UPASS@$OSID
whenever sqlerror continue

@script1
@script2
@script3
@script4
@script5

EOF
#
# Report if connection attempt was bad
#

status=$?

if [ $status -eq 51 ]
then

        echo "User ID $UID or password $UPASS is incorrect"
        exit 3

fi

David Fitzjarrell Received on Tue Nov 07 2006 - 15:39:23 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US