Q4.1: Hiding your password to isql


Here are a menagerie (I've always wanted to use that word) of different methods to hide your password. Pick and choose whichever fits your environment best:

Single SQL Server on host

Script #1

Assuming that you are using bourne shell sh(1) as your scripting language you can put the password in a file and substitute the file where the password is needed.
#!/bin/sh

# invoke say ISQL or something....
( cat $HOME/dba/password_file
  cat << EOD
dbcc ...
go
EOD
 ) |
$SYBASE/bin/isql -U sa -w1000

Script #2

#!/bin/sh
umask 077
cat <<-EndOfCat | isql -Umyuserid -Smyserver
        mypassword
        use mydb
        go
        sp_who
        go
EndOfCat

Script #3

 
#!/bin/sh
umask 077
cat <<-EndOfCat | isql -Umyuserid -Smyserver
        `myScriptForGeneratingPasswords myServer`
        use mydb
        go
        sp_who
        go
EndOfCat

Script #3

 
#!/bin/sh
umask 077
isql -Umyuserid -Smyserver <<-EndOfIsql
        mypassword
        use mydb
        go
        sp_who
        go
EndOfIsql

Script #4

 
#!/bin/sh
umask 077
isql -Umyuserid -Smyserver <<-EndOfIsql
        `myScriptForGeneratingPasswords myServer`
        use mydb
        go
        sp_who
        go
EndOfIsql

Script #5

 
#!/bin/sh
echo 'mypassword
use mydb
go
sp_who
go' | isql -Umyuserid -Smyserver

Script #6

 
#!/bin/sh
echo "`myScriptForGeneratingPasswords myServer`
use mydb
go
sp_who
go" | isql -Umyuserid -Smyserver

Multiple SQL Servers on host

Again, assuming that you are using bourne shell as your scripting language, you can do the following:
  1. Create a global file. This file will contain passwords, generic functions, master device for the respective DSQUERY.
  2. In the actual scripts, source in the global file.

Script #7

#!/bin/sh
echo "Password :\c "
stty -echo
read PASSWD
stty echo

echo "$PASSWD
waitfor delay '0:1:00'
go
" | $SYBASE/bin/isql -U sa -S $DSQUERY

Global File


SYBASE=/usr/sybase

my_password()
{
   case $1 in
      SERVER_1)  PASSWD="this";;
      SERVER_2)  PASSWD="is";;
      SERVER_3)  PASSWD="bogus;;
      *) return 1;;
   esac

   return 0
}

Generic Script

#!/bin/sh -a

#
# Use "-a" for auto-export of variables
#

# "dot" the file - equivalent to csh() "source" command
. $HOME/dba/global_file

DSQUERY=$1

# Determine the password:  sets PASSWD
my_password $DSQUERY
if [ $? -ne 0 ] ; then # error!
   echo ""
   exit 1
fi

# invoke say ISQL or something....
echo "$PASSWD
dbcc ...
go" | $SYBASE/bin/isql -U sa -S $DSQUERY -w1000