From the SQL*Plus help doc (sqlplus --help
):
Usage 2: sqlplus [ [<option>] [{logon | /nolog}] [<start>] ]
...
<start> is: @<URL>|<filename>[.<ext>] [<parameter> ...]
This means you can supply a path to a script which will run as soon as you connect/login.
The absolute basic example of this is to echo 'exit' to a file, then run that file, e.g.
C:\>echo exit > exit.tmp
C:\>sqlplus /nolog @exit.tmp
SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 14 15:34:35 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
C:\>del exit.tmp
Of course, above I have not logged into a database, so I have not really checked a database. If you want to check a specific tnsnames.ora
entry, you will probably need to supply full credentials for that service on the command line (there are possible security ramifications of that), otherwise the 'exit' issued by your script will probably get absorbed by the Username prompt normally issued by sqlplus (either that, or your script will hang at the Username prompt).
J.