From: WINUX on
Hi all,

I am creating a expect script that logs in and does a su - whereafter
I want to be able to interactively use the logged in ssh session.

I have been searching to fix this for a long time but without luck:

spawn /usr/bin/ssh -o StrictHostKeyChecking=no -l theuser x.x.x.x
expect "*?assword:*" {send "theuserpassword\r"}
sleep 2
expect "\$*" {send "su -\r"}
sleep 2
expect "*?assword:*" {send "rootpassword\r"; sleep 2}
interact

However it always exits just after root login has finished. (which is
actually succesfully)

expect version 5.43.0
argv[0] = expect argv[1] = -d
set argc 0
set argv0 "expect"
set argv ""
executing commands from command file
spawn /usr/bin/ssh -o StrictHostKeyChecking=no -l theuser x.x.x.x
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {22404}

expect: does "" (spawn_id exp11) match glob pattern "*?assword:*"? no
theuser(a)x.x.x.x's password:
expect: does "theuser(a)x.x.x.x's password: " (spawn_id exp11) match
glob pattern "*?assword:*"? yes
expect: set expect_out(0,string) "theuser(a)x.x.x.x's password: "
expect: set expect_out(spawn_id) "exp11"
expect: set expect_out(buffer) "theuser(a)x.x.x.x's password: "
send: sending "loginpass\r" to { exp11 }

expect: does "" (spawn_id exp11) match glob pattern "$*"? no


expect: does "\r\n" (spawn_id exp11) match glob pattern "$*"? no
Last login: Mon Aug 31 22:32:54 2009 from x.x.x.x

expect: does "\r\nLast login: Mon Aug 31 22:32:54 2009 from x.x.x.x\r\r
\n" (spawn_id exp11) match glob pattern "$*"? no

expect: does "\r\nLast login: Mon Aug 31 22:32:54 2009 from x.x.x.x\r\r
\n\u001b]0;theuser(a)thehost:~\u0007" (spawn_id exp11) match glob
pattern "$*"? no
[theuser(a)thehost ~]$
expect: does "\r\nLast login: Mon Aug 31 22:32:54 2009 from x.x.x.x\r\r
\n\u001b]0;theuser(a)theuser:~\u0007[theuser(a)theuser ~]$ " (spawn_id
exp11) match glob pattern "$*"? yes
expect: set expect_out(0,string) "$ "
expect: set expect_out(spawn_id) "exp11"
expect: set expect_out(buffer) "\r\nLast login: Mon Aug 31 22:32:54
2009 from x.x.x.x\r\r\n\u001b]0;theuser(a)thehost:~\u0007
[theuser(a)thehost ~]$ "
send: sending "su -\r" to { exp11 }

expect: does "" (spawn_id exp11) match glob pattern "*?assword:*"? no
su -
Password:
expect: does "su -\r\nPassword: " (spawn_id exp11) match glob pattern
"*?assword:*"? yes
expect: set expect_out(0,string) "su -\r\nPassword: "
expect: set expect_out(spawn_id) "exp11"
expect: set expect_out(buffer) "su -\r\nPassword: "
send: sending "thesupassword\r" to { exp11 }
spawn id exp11 sent <\r\n\u001b]0;root(a)thehost:~\u0007[root(a)thehost ~]
# >

[root(a)thehost ~]# interact: received eof from spawn_id exp0
I would expect Expect to wait until I finished the interact part to
finish or the ssh process exited (which seems most logical in this
case, after doing exit I exit ssh and Expect exits).
Does anyone knows how to fix this?

THis is written in a variable! So not written in a file (I try to
circumvent having passwords in a file).
If I put this in a file it normally works.
I found something about end_eof or something like that but seems that
this is not available anymore(I assume that it was for Expect not to
exit when the end of the file was reached).

help will be much appreciated!

NOTE: please don't give me advice to get to use RSA keys. I know they
exist, how they work and how I should configure it.
However, in this particular case it is not an option.
From: WINUX on
close_on_eof 0
That was the one I found