spawn与except组合可达到远程登录设备执行命令的作用

下面是登录设备的一段代码

#!/usr/bin/expect -f

user=root

host=1.1.1.1

password=root

spawn $user@$host
set timeout 60
except {
  "(yes/no)?" {

    send "yes\n"

    expect "*assword:*"
    send "$password\n"
   }
  "assword:" {
    send "$password\n"

  } timeout {
    exit
  } eof{
    exit
  }
}

相关文章:

  • 2021-05-17
  • 2021-08-29
  • 2021-07-03
  • 2022-01-10
  • 2021-09-15
  • 2021-11-06
  • 2021-11-07
猜你喜欢
  • 2021-10-20
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案