|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Looping/Reading file contents not working
Hi, I am doing something basic, but I am missing something. Im trying to read the contents of a file and taking those values and connecting to a database. However, it only connect to one (or reads in) value and then exists. Here is what it looks like: listname.txt Code:
db1 db2 db3 Script: Code:
dbcontent=/usr/home/listname.txt echo "Enter userid" read USERID echo "Enter passwd:" stty -echo read -s PASSWD stty echo while read dbname; do #Connect to SQLPlus sqlplus -S test/test123@$dbname << EOF select ora_database_name from dual; prompt my name is $USERID and my password is $PASSWD; exit; EOF done < $dbcontent It doesn't read all the lines (loop through) just exits after one run. I am also trying to have it connect to each database (in the list). Last edited by DBnixUser; 01-30-2013 at 07:51 PM.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
sqlplus -S test/test123@$dbname << EOF |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Sorry I forgot to add that. I have that already.
|
|
#4
|
|||
|
|||
|
At first sight your code looks correct (save for some minor things which shouldn't matter here), so try to isolate the problem. What does Code:
typeset dbcontent="/usr/home/listname.txt"
typeset dbname=""
echo "Enter userid"
read USERID
echo "Enter passwd:"
stty -echo
read -s PASSWD
stty echo
while read dbname; do
echo "DBNAME is: $dbname"
#Connect to SQLPlus
#sqlplus -S test/test123@$dbname << EOF
#select ora_database_name from dual;
#prompt my name is $USERID and my password is $PASSWD;
#exit;
#EOF
done < "$dbcontent"do? Does it still go only once through the loop, then probably something with the input file is wrong (unprintable characters or the like). Is the problem gone, then something with the sqlplus-command is responsible. Either way you know more then than you know now. I hope this helps. bakunin |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
No, this works just fine. I tried that also to make sure it is actually looping.
Thanks. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Do you get an error (exit status != 0) from the DB operations? In bash (you unfortunately don't mention what system you use), setting the -e option (not shown in your code snippet) will immediately exit on an error condition.
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
Sorry I am using korn shell (/bin/ksh). |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading file contents until a keyword | infintenumbers | Shell Programming and Scripting | 2 | 07-31-2012 04:23 PM |
| While or For with looping contructs? to create files from contents of a text file | wolf@=NK | Shell Programming and Scripting | 3 | 05-23-2012 06:15 AM |
| reading file,looping and limitation | Jang | Shell Programming and Scripting | 5 | 10-28-2011 02:48 PM |
| Reading and printing one by one contents of a file | Aditya.Gurgaon | Shell Programming and Scripting | 2 | 01-27-2009 05:08 AM |
| Reading specific contents from a file and appending it to another file | dnicky | Shell Programming and Scripting | 5 | 10-04-2005 05:45 AM |
|
|