expect, interact and then again expect

后端 未结 2 1781
我在风中等你
我在风中等你 2021-02-09 07:50

There are several posts regarding the same, but i still not able to make my expect script work properly. My intention is to automate everything but leave the password enter for

2条回答
  •  旧时难觅i
    2021-02-09 08:08

    You can read (expect_user) the user's password by yourself and then send it to the spawn'ed program. For example:

    [STEP 101] # cat foo.exp
    proc expect_prompt {} \
    {
        global spawn_id
        expect -re {bash-[.0-9]+(#|\$)}
    }
    
    spawn ssh -t 127.0.0.1 bash --noprofile --norc
    expect "password: "
    
    stty -echo
    expect_user -timeout 3600 -re "(.*)\[\r\n]"
    stty echo
    send "$expect_out(1,string)\r"
    
    expect_prompt
    send "exit\r"
    expect eof
    [STEP 102] # expect foo.exp
    spawn ssh -t 127.0.0.1 bash --noprofile --norc
    root@127.0.0.1's password:
    bash-4.3# exit
    exit
    Connection to 127.0.0.1 closed.
    [STEP 103] #
    

提交回复
热议问题