1

I have an expect script that is exiting, instead of processing text that is sent and installing files. I'm trying to figure out why it's not installing files, i.e. not implementing what would be done had I run the process manually instead of via expect.

I have the following code in my script:

#!/usr/bin/expect
set exp_internal 1

set timeout 30
set java [lindex $argv 0];
set installer [lindex $argv 1];

spawn $java -jar $installer -console

expect {
        "*More*" { send " "; exp_continue }
        "Press 1 to accept, 2 to reject, 3 to redisplay" { send "1\r" }
}

expect "Select the installation path:*" { send "/opt/pentaho8.3\r" }

expect "Press 1 to continue, 2 to quit, 3 to redisplay\r\n" { send "1\r" }

close
exit

When I run the script as follows:

$ sudo /usr/bin/expect -d install-pentaho.expect /usr/java/jdk1.8.0_261/bin/java pentaho-server-manual-ee-8.3.0.0-371/installer.jar

It runs as expected, except for the last couple lines:

send: sending "/opt/pentaho8.3\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "Press 1 to continue, 2 to quit, 3 to redisplay\r\n"? no
/opt/pentaho8.3

expect: does "/opt/pentaho8.3\r\r\n" (spawn_id exp6) match glob pattern "Press 1 to continue, 2 to quit, 3 to redisplay\r\n"? no

Press 1 to continue, 2 to quit, 3 to redisplay

    expect: does "/opt/pentaho8.3\r\r\n\r\nPress 1 to continue, 2 to quit, 3 to redisplay\r\n" (spawn_id exp6) match glob pattern "Press 1 to continue, 2 to quit, 3 to redisplay\r\n"? yes
    expect: set expect_out(0,string) "Press 1 to continue, 2 to quit, 3 to redisplay\r\n"
    expect: set expect_out(spawn_id) "exp6"
    expect: set expect_out(buffer) "/opt/pentaho8.3\r\r\n\r\nPress 1 to continue, 2 to quit, 3 to redisplay\r\n"
    send: sending "1\r" to { exp6 }

Anyone have thoughts as to why the '1' being sent by expect is getting ignored? It seems that the spawned process is exiting, ignoring the '1' that is sent.

Below is the expected output, i.e. what I get when I run sudo /usr/java/jdk1.8.0_261/bin/java -jar pentaho-server-manual-ee-8.3.0.0-371/installer.jar -console manually:

Select the installation path:  [/root/pentaho/pentaho-server-manual-ee-8.3.0.0-371]
/opt/pentaho8.3

Press 1 to continue, 2 to quit, 3 to redisplay
1

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Installation
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

[ Starting to unpack ]
[ Processing package: Base (1/1) ]
[ Unpacking finished ]

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Installation Finished
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Installation was successful
Application installed on /opt/pentaho8.3
[ Console installation done ]

Any thoughts on why the installation is not occurring, and the expect script is exiting prematurely?

3
  • 1
    If you change close to expect eof does it fix the issue? I would expect (sorry, I couldn't help it) there to be more debug information at the end but I am not near a machine to try it.
    – icarus
    Sep 21, 2020 at 22:18
  • Awesome! That fixed it. Thanks a million!
    – Burvil
    Sep 21, 2020 at 22:44
  • Yes, when your expect script exits too quickly, the spawned process will get killed before it has a chance to finish. Sep 21, 2020 at 23:20

1 Answer 1

0

The problem is that you are closing the connection to the Java program, so when it writes some messages it gets SIGPIPE and exits.

Change the close to expect eof (and maybe adjust the timeout if it takes longer than 30 seconds to do the install). This makes expect wait until the program has finished (or at least until it closes stdout).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .