Friday, August 31, 2012

Login from Unix to any database and running a query

Script below is used to login by any user and to keep the password hidden (not displayed on the screen)

#!/bin/bash
#Usage
# Pass Username & Connectsting
#password will be asked at login time
#read -s is used to hide password and it will not been displayed to the user

if [ "$1" = "" ] || [ "$2" = "" ]; then
   echo "Please pass Username and Database name to connect"
else
echo "Enter Pass"
read -s password
sqlplus -s "$1/$password@$2" << EOF
select sysdate from dual
/
EOF
fi

No comments:

Post a Comment