Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Shell Script Heros
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
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
#
# 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
status=$?
if [ $status -eq 51 ]
then
echo "User ID $UID or password $UPASS is incorrect" exit 3
David Fitzjarrell Received on Tue Nov 07 2006 - 15:39:23 CST
![]() |
![]() |