loop to read multiple username and password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop to read multiple username and password
# 1  
Old 07-16-2011
loop to read multiple username and password

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 ??

https://www.unix.com/shell-programmin...ass-shell.html
# 2  
Old 07-16-2011
You can extract the first field with awk:

Code:
awk -F, '{print $1}' sid.txt
db1
db2
db3

# 3  
Old 07-16-2011
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
$
# 4  
Old 07-16-2011
Try to put this code in a variable instead and let the for loop parse that:

Code:
USER=`cat /home/oracle/sidlist|awk -F, '{print $1}`

and then
Code:
for ORACLE_SID in $USER

and exchange $user1 with $USER in the connect part of your script.
This User Gave Thanks to jostber For This Post:
# 5  
Old 07-17-2011
Quote:
Originally Posted by jostber
Try to put this code in a variable instead and let the for loop parse that:

Code:
USER=`cat /home/oracle/sidlist|awk -F, '{print $1}`

and then
Code:
for ORACLE_SID in $USER

and exchange $user1 with $USER in the connect part of your script.
Thanks ...that did the deal....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[SOLVED] UNIX FOR loop to read a variable with multiple values

Hi, I have a variable which stores file names as a result of find command. I need to delete all these files one by one, i.e. by a loop. Can anyone tell me how can it be done? The variable f2d has the file names like these abc.txt bcd.txt fff.txt gef.txt Now I have used a loop as... (12 Replies)
Discussion started by: jhilmil
12 Replies

2. UNIX for Dummies Questions & Answers

How do you reset username/password

Picked up a 3b2 running System V. Works fine, but it requires a username and password. Is the username "root" or "sysadm"? How do I find out and how to I reset it or bypass it? Thanks. (2 Replies)
Discussion started by: TanRuNomad
2 Replies

3. Shell Programming and Scripting

Username and password

Hi I am new to using unix and am struggling with a script i am writing. What i am trying to do is get a user to enter a username, check the original file i created with username and pin to see if their is a corresponding entry. Next ask the user to enter the pin and see if this matches... (5 Replies)
Discussion started by: somersetdan
5 Replies

4. Shell Programming and Scripting

Username password asked during loging

Hi, Whenever I open my unix box,after providing username and password I get the following message. Are you authorised to use this computer as detailed above? (Y)es/(N)o : y Export: Release 10.2.0.2.0 - Production on Mon May 16 16:00:15 2011 Copyright (c) 1982, 2005, Oracle. All rights... (5 Replies)
Discussion started by: emilybose
5 Replies

5. UNIX for Advanced & Expert Users

Login through SFTP using username and password

Hi All, I want to login to a server through SFTP by giving username and password, in an automated script. I know that this can be done through public key authentication, but my requirement is to login ONLY through username and password. I am using GNU/Linux server. Please advise me !!!... (4 Replies)
Discussion started by: sparks
4 Replies

6. Shell Programming and Scripting

Read and edit multiple files using a while loop

Hi all, I would like to simply read a file which lists a number of pathnames and files, then search and replace key strings using a few vi commands: :1,$s/search_str/replace_str/g<return> but I am not sure how to automate the <return> of these vis commands when I am putting this in a... (8 Replies)
Discussion started by: cyberfrog
8 Replies

7. UNIX for Dummies Questions & Answers

How can i hide username/password

hi all, i run sqlplus command on unix(HP-UX) like "sqlplus username/password@serverA @deneme.sql" but when someone run "ps -ef | grep sqlplus", it can see my username and password :( How can i hide username and password. thanx. (1 Reply)
Discussion started by: temhem
1 Replies

8. Shell Programming and Scripting

Read multiple arguments in for loop each time

Hi, Guys I am new to shell programming and just get stuck with one simple question. please kindly help. According to the tutorial here, we can do something like for NODE in "ABC 10" "EFG 20" do set -- $NODE echo "letter is $1, number is $2" done And the result will... (3 Replies)
Discussion started by: yuanli
3 Replies

9. Shell Programming and Scripting

Read Oracle Username password SID from single file and pass it to shell

Dear All I am trying to write one shell which will be running through Cron which contain one SQL query. But I want to draw/fetch the Username password and Instance name (required to loging to the database) from one single file to run that SQL query . Also this file contain details of multiple... (2 Replies)
Discussion started by: jhon
2 Replies

10. Shell Programming and Scripting

username password in script

Can we write a script to telnet to a unix server from unix with the username and password hardcoded in the script?? something like ssh a@b -p password ??? (5 Replies)
Discussion started by: roshanjain2
5 Replies
Login or Register to Ask a Question