美文网首页
Expect : SSH login

Expect : SSH login

作者: 喷射的熔浆 | 来源:发表于2018-02-24 18:39 被阅读0次

    Syntax

    # assign variables
    set variable_name variable_value
    # do bash
    spawn .....
    # expect
    expect ...
    # send
    send "..."
    # interact
    interact
    

    Examples

    #!/usr/bin/expect -f
    set ipaddr "localhost"
    set passwd "iforgot"
    spawn ssh root@$ipaddr
    expect {
    "yes/no" { send "yes\r"; exp_continue}
    "password:" { send "$passwd\r" }
    }
    expect "]# "
    send "touch a.txt\r" 
    send "exit\r"
    expect eof
    exit
    
    
    

    References

    1. how to use regex in switch case in expect script?
    2. Embedding an expect inside a bash script
    3. How do I embed an expect script that takes in arguments into a bash shell script?
    4. 6 Expect Script Command Line Argument Examples

    相关文章

      网友评论

          本文标题:Expect : SSH login

          本文链接:https://www.haomeiwen.com/subject/vukcxftx.html