Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-31-2009, 03:40 PM
|
#1
|
Member
Registered: Aug 2006
Posts: 609
Rep:
|
Expect script exiting unexpectedly (eof)
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:
Quote:
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)
Quote:
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@x.x.x.x's password:
expect: does "theuser@x.x.x.x's password: " (spawn_id exp11) match glob pattern "*?assword:*"? yes
expect: set expect_out(0,string) "theuser@x.x.x.x's password: "
expect: set expect_out(spawn_id) "exp11"
expect: set expect_out(buffer) "theuser@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@thehost:~\u0007" (spawn_id exp11) match glob pattern "$*"? no
[theuser@thehost ~]$
expect: does "\r\nLast login: Mon Aug 31 22:32:54 2009 from x.x.x.x\r\r\n\u001b]0;theuser@theuser:~\u0007[theuser@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@thehost:~\u0007[theuser@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@thehost:~\u0007[root@thehost ~]# >
[root@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?
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.
Last edited by deadeyes; 08-31-2009 at 03:45 PM.
|
|
|
08-31-2009, 04:30 PM
|
#2
|
Member
Registered: Aug 2006
Posts: 609
Original Poster
Rep:
|
I have found something I think.
What I actually want to do is to execute a expect script without actually creating the file.
So if I do expect -f thefile it works, however with expect < thefile or with doing a echo $thescriptvariable | expect it does not work.
|
|
|
08-31-2009, 09:29 PM
|
#3
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
Good that you found the solution yourself, because I would never have been able to guess it!
Anyway, it is clear that you interact session want to interact with stdin. However you were reading the script already from stdin, and that seems to clash. I am afraid that this is a preclusion which cannot be solved, you can't interact and pipe your script in expect at the same time.
jlinkels
|
|
|
09-01-2009, 02:21 AM
|
#4
|
Member
Registered: Aug 2006
Posts: 609
Original Poster
Rep:
|
Quote:
Originally Posted by jlinkels
Good that you found the solution yourself, because I would never have been able to guess it!
Anyway, it is clear that you interact session want to interact with stdin. However you were reading the script already from stdin, and that seems to clash. I am afraid that this is a preclusion which cannot be solved, you can't interact and pipe your script in expect at the same time.
jlinkels
|
I found this behaviour very strange.
If you read from a file at the EOF, this is the same as with stdin, so I dont understand the different behaviour.
Also, this makes the stdin functionality "useless".
I really want to use stdin as this is wont write any file to disk with passwords.
|
|
|
09-01-2009, 07:47 AM
|
#5
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
Quote:
Originally Posted by deadeyes
I really want to use stdin as this is wont write any file to disk with passwords.
|
I assume that problem exists because with the interact command expect considers the script which it is reading from stdin is not finished yet.
But if you pipe the contents of your script file into expect, you must have that password somewhere in the file you are piping into expect, right?
Anyway, storing a password in clear in a 600 permissed file is a completely accepted safety policy. You could consider to have the password file somewhere else and include it in the expect script.
jlinkels
|
|
|
09-02-2009, 02:23 AM
|
#6
|
Member
Registered: Aug 2006
Posts: 609
Original Poster
Rep:
|
Quote:
Originally Posted by jlinkels
I assume that problem exists because with the interact command expect considers the script which it is reading from stdin is not finished yet.
But if you pipe the contents of your script file into expect, you must have that password somewhere in the file you are piping into expect, right?
Anyway, storing a password in clear in a 600 permissed file is a completely accepted safety policy. You could consider to have the password file somewhere else and include it in the expect script.
jlinkels
|
THanks for your comment.
I don't have to write a password to a file if reading from stdin would work.
Passwords are not on the local machine and I assemble the script in a variable. All goes well until the interact statement.
I will try to find maybe a solution on the tcl newsgroup.
I found on google some results with end_eof 0 or something like that but it seems that this is not in the latest versions anymore.
|
|
|
All times are GMT -5. The time now is 06:18 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|