[linux系统]--spawn 用法

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
  }
}

posted @ 2016-09-19 20:01  joangaga  阅读(12022)  评论(0编辑  收藏  举报