Hello all, I am i am trying to read username password. Bassicaly, i have file called sidlist and it has my database name, username and password....
looks something like this....
db1, user1, pass1
db2, user2, pass2
db3, user3, pass4
but i dont know how to make it work, until i get rid of user1 and pass1...like below...and only have db1 (database name)...to login to sqlplus...
how can read the parameter2 (username) and parameter3(password) and pass that in a loop ??
$ cat test.sh
###########################
# Check for the oratab file.
###########################
ORATAB=/etc/oratab
##now cat for sid list
for ORACLE_SID in `cat /home/oracle/sidlist`
do
################################################
# Build list of distinct Oracle Home directories.
################################################
OH=`egrep -i ":Y|:N" $ORATAB |grep $ORACLE_SID| grep -v "^#" | grep -v "\*" | cut -d":" -f2 | sort | uniq`
echo $ORACLE_SID
echo $OH
#############################
# Set the Oracle environment.
##############################
ORAENV_ASK=NO
export ORACLE_SID
. oraenv
which sqlplus
echo '#####################################################################################'
done
$
$
$
$ cat sidlist
test
mihran
$
i found this below link...that gives me a idea how to use it....but then how would i use that in a loop ??
You can extract the first field with awk:
awk -F, '{print $1}' sid.txt
db1
db2
db3
how would i read the password in a loop then...how would i read the diff password in a loop then ?? obviously one at a time...
db1, user1, pass1
db2, user2, pass2
as of now...my script looks like this...but it only works...as i have user1 hardcoded in it...its not ussing pass1, pass2 for each db....
$ cat test.sh
user1=system/abc123
###########################
# Check for the oratab file.
###########################
ORATAB=/etc/oratab
##now cat for sid list
for ORACLE_SID in `cat /home/oracle/sidlist|awk -F, '{print $1}'`
do
################################################
# Build list of distinct Oracle Home directories.
################################################
OH=`egrep -i ":Y|:N" $ORATAB |grep $ORACLE_SID| grep -v "^#" | grep -v "\*" | cut -d":" -f2 | sort | uniq`
echo $ORACLE_SID
echo $OH
#############################
# Set the Oracle environment.
##############################
ORAENV_ASK=NO
export ORACLE_SID
. oraenv
which sqlplus
sqlplus /nolog << EOF
connect $user1
@test.sql
EOF
echo '#####################################################################################'
done
$
$
$
$ cat sidlist
test, pass1
mihran, pass2
$
Try to put this code in a variable instead and let the for loop parse that:
USER=`cat /home/oracle/sidlist|awk -F, '{print $1}`
and then
for ORACLE_SID in $USER
and exchange $user1 with $USER in the connect part of your script.
1 Like
Thanks ...that did the deal....