Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

expect and sqlplus

414 views
Skip to first unread message

Joe Kazimierczyk

unread,
Oct 15, 2001, 12:08:30 PM10/15/01
to
I'm using the following unix expect script to interact the Oracle
sqlplus utility. Sqlplus prompts for a password, expect sends the password,
then I 'interact'. Most of the time this works, but every once in a
while, the password shows on the screen, and expect just sits there
waiting for something, and doesn't make it to interact. If I put in a
'sleep 1', I don't have this problem, but am not sure why. Any
pointers? I'd like to (1) avoid the delay if possible, and (2) insure
that the password never shows even with the 'sleep', but without knowing
what's happening, I'm not confident that 'sleep 1' will always work.


#!/usr/local/bin/expect --
set usern "testuser"
set passw [exec aprogramtogetpassword $usern]
set timeout -1
eval spawn sqlplus $usern
log_user 0
expect "Enter password: "
# why do I need the following sleep?:
sleep 1
send "$passw\r"
log_user 1
expect {
"Enter user-name: " exit
"Connected"
}
interact

Gary L. Burnore

unread,
Oct 15, 2001, 12:39:32 PM10/15/01
to
On 15 Oct 2001 09:08:30 -0700, in article
<e2242da1.01101...@posting.google.com>, kazi...@bms.com (Joe
Kazimierczyk) wrote:

Oracle's sql is taking too long to do the "stty -echo" required to hide the
password. You're doing the right thing by adding a sleep of a second or two.

--
gburnore at DataBasix dot Com
---------------------------------------------------------------------------
Are you going to Scarborough Fair?
---------------------------------------------------------------------------
Gary L. Burnore | нлГКнГоГКнГГнлКнГоГКнГнГоГКнГннлГ
| нлГКнГоГКнГГнлКнГоГКнГнГоГКнГннлГ
Official .sig, Accept no substitutes. | нлГКнГоГКнГГнлКнГоГКнГнГоГКнГннлГ
| нл 0 1 7 2 3 / нГо 3 7 4 9 3 0 лГ
Black Helicopter Repair Services, Ltd.| Official Proof of Purchase
===========================================================================

Ashwin Baskaran

unread,
Oct 15, 2001, 12:50:34 PM10/15/01
to
kazi...@bms.com (Joe Kazimierczyk) writes:


> while, the password shows on the screen, and expect just sits there
> waiting for something, and doesn't make it to interact. If I put in a
> 'sleep 1', I don't have this problem, but am not sure why. Any
> pointers? I'd like to (1) avoid the delay if possible, and (2) insure
> that the password never shows even with the 'sleep', but without knowing
> what's happening, I'm not confident that 'sleep 1' will always work.

(You can get this text by using autoexpect to autogenerate an expect script)

# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.


More information may be available in the Exploring Expect book, or on
comp.lang.tcl.


Ashwin
--
Ashwin Baskaran
Cisco Systems

Oliver Kiessling

unread,
Oct 16, 2001, 3:40:46 AM10/16/01
to
kazi...@bms.com (Joe Kazimierczyk) wrote in message news:<e2242da1.01101...@posting.google.com>...

Did you try to call sqlplus like this:

sqlplus /NOLOG

You will get a SQL> prompt and can connect:

SQL> connect <user>/<passwd>@<ORACLE_SID>

- Oliver

0 new messages