Expect within a Bash script

后端 未结 3 982
無奈伤痛
無奈伤痛 2020-12-31 13:04

I wrote a Bash script with Expect within, to connect to a terminal server and clear lines.

I am unable to figure out the error I am getting, as in I have given all th

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 13:37

    The problem is that that the double quotes in the Expect script are treated as the end of the Expect script. Try mixing single quotes with double quotes:

    #!/bin/bash
    VAR=$(expect -c '
    spawn telnet 1.1.1.1
    expect {
    "Password:" { send "password\r" ; exp_continue}
    "Prompt>" { send "en\r" ; exp_continue}
    "Password:" { send "password\r" ; exp_continue}
    "Prompt#" {send "clea line 10\r" ; exp_continue}
    "[confirm]" {send "Y\r" ; exp_continue}
    "Prompt#" {send "clea line 11\r" ; exp_continue}
    "[confirm]" {send "Y\r" ; exp_continue}
    "Prompt#" {send "exit\r" }
    }
    ')
    

提交回复
热议问题