For loop help with sqlplus

When I run this command it works fine.

: echo exit|sqlplus username/password@database_name

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Nov 17 15:37:52 2023
Version 19.21.0.0.0

Copyright (c) 1982, 2022, Oracle.  All rights reserved.

Last Successful login time: Fri Nov 17 2023 15:28:43 -06:00

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.21.0.0.0

SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.21.0.0.0

When I run this command I have issues. It looks like my $1 is not expanding correctly.

: for i in `cat database_list`; do echo $i; echo exit|sqlplus username/password@$1; done
database_name

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Nov 17 15:47:47 2023
Version 19.21.0.0.0

Copyright (c) 1982, 2022, Oracle.  All rights reserved.

ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified


Enter user-name: Enter password:
ERROR:
ORA-12162: TNS:net service name is incorrectly specified


Enter user-name: database_name

How is this invoked
What is $1 , how is it passed

It come from my database_list file. It has a big list of databases. I knocked it down to two databases for testing purposed.

`cat database_list`

What does cat -vet database_list output?

Are you sure you are not mixing $i and $1 here ?
What shell are you using ?

What is end goal, to test multiple user/pw against various oracle TNS entries ?

Regards
Peasant.

2 Likes

show the contents of database_list file please

the less you show, the harder it's for us to give meaningful responses

the user has requested we delete the post .... $i $1 issue they've resolved on there own.

I would not delete it since it does not contain any private data and could help others with similar issues ?

In any case, testing user/pw against database can be done in much cleaner ways, even with sqlplus :wink:

1 Like

60 databases*.

How? Would love a cleaner way to check 60 databases.

@Peasant Can you please tell me about the cleaner ways?

@Peasant Can you please tell me about the cleaner ways?