Поток ожидаемого сценария не работает должным образом - PullRequest
0 голосов
/ 23 октября 2019

У меня были некоторые ожидаемые сценарии, как показано ниже, и я путаюсь с рабочим процессом.

[/home/VB] >cat common_functions.sh
#!/bin/sh

# the next line restarts using expect \
exec expect "$0" "$@"

proc wait_for_prompt {prompt {s 90}} {
    puts "wait_for_prompt calling ..."
    set timeout $s

    expect {
        $prompt {}
    }
}

proc handle_login { args } {
    puts "handle_login calling ..."

    expect {
        ":~#" {puts "handle_login accessed to remote"}
    }
}

[/home/VB] >cat test_expect_with_source.sh
#!/bin/sh

# the next line restarts using expect \
exec expect "$0" "$@"

source common_functions.sh

set remote_ip [lindex $argv 0]
set remote_remote_host [lindex $argv 1]
set timeout 5

puts "test_expect_with_source calling ..."

log_user 1
spawn ssh -o ConnectTimeout=3 root@$remote_ip

handle_login

puts "zone to access second remote"
after 1500
send "ssh $remote_remote_host\r"

wait_for_prompt ":*#"

...

[/home/VB] >./test_expect_with_source.sh 192.168.100.10 TESTING_MACHINE.TEST.HOST
test_expect_with_source calling ...
spawn ssh -o ConnectTimeout=3 root@192.168.100.10
handle_login calling ...
Last login: Wed Oct 23 07:42:25 2019 from 192.168.100.20
VB_machine:~# handle_login accessed to remote
zone to access second remote
wait_for_prompt calling ...    (confuse between this line)
ssh TESTING_MACHINE.TEST.HOST  (and this line)
...

В выводе при выполнении test_expect_with_source.sh я не понимаю, почему функция wait_for_prompt выполнялась до ssh $ remote_remote_host

Пожалуйста, помогите мне в этом.

Большое спасибо.

...