LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 08-31-2009, 03:40 PM   #1
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
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.
 
Old 08-31-2009, 04:30 PM   #2
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Original Poster
Rep: Reputation: 79
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.
 
Old 08-31-2009, 09:29 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,194

Rep: Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040
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
 
Old 09-01-2009, 02:21 AM   #4
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Original Poster
Rep: Reputation: 79
Quote:
Originally Posted by jlinkels View Post
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.
 
Old 09-01-2009, 07:47 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,194

Rep: Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040
Quote:
Originally Posted by deadeyes View Post
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
 
Old 09-02-2009, 02:23 AM   #6
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Original Poster
Rep: Reputation: 79
Quote:
Originally Posted by jlinkels View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
Very n00b question about exiting a bash script wimnat Linux - Software 11 05-28-2009 08:11 PM
Script refuses to run section in '<<EOF' nukeu666 Linux - General 6 09-11-2008 04:53 AM
500 EOF instead of reponse status line in perl script Sherlock Programming 7 05-16-2007 06:52 AM
Gimp crashes suddenly LibGimp-WARNING **: script-fu: wire_read: unexpected EOF anorman Linux - Software 0 03-12-2004 12:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration