我正在使用 expect 在我的服务器上启动一个应用程序:
#!/usr/bin/expect
set timeout -1
spawn "bin/start-all.sh"
expect {
-re "Found MongoDB in" { send "y\r"; exp_continue }
-re "Found Hadoop in" { send "y\r"; exp_continue }
-re "Going to start Hadoop" { interact }
}
我可以在脚本运行的几秒钟内访问我的服务器上的应用程序,但一旦它结束,应用程序就变得不可用。
我已经在调试模式下运行 expect 并在最后得到以下输出:
expect: does "vendors area. Do you want to start it? [y/n] y\r\n" (spawn_id exp6) match regular expression "Found MongoDB in"? Gate "Found MongoDB in"? gate=no
"Found Hadoop in "? Gate "Found Hadoop in "? gate=no
"Going to start Hadoop"? Gate "Going to start Hadoop"? gate=no
Going to start Hadoop...
expect: does "vendors area. Do you want to start it? [y/n] y\r\nGoing to start Hadoop...\r\n" (spawn_id exp6) match regular expression "Found MongoDB in"? Gate "Found MongoDB in"? gate=no
"Found Hadoop in "? Gate "Found Hadoop in "? gate=no
"Going to start Hadoop"? Gate "Going to start Hadoop"? gate=yes re=yes
expect: set expect_out(0,string) "Going to start Hadoop"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "vendors area. Do you want to start it? [y/n] y\r\nGoing to start Hadoop"
tty_raw_noecho: was raw = 0 echo = 1
interact: received eof from spawn_id exp6
tty_set: raw = 0, echo = 1
tty_set: raw = 5, echo = 0
我已经尝试在最后一种模式下使用exit 0
, interact
, exp_continue
, disconnect
,sleep 10
以及期待eof
但似乎没有任何效果。我也尝试过跑步expect start-all.exp &
,但这也不起作用。
当我手动运行 bin/start-all.sh 时,脚本会启动必要的进程然后退出。然而,期望这些进程似乎被杀死了。我将如何解决这个问题?