expect 远程执行命令-02

+++++++++++++++++++++++++++++++++++++

标题:expect 远程执行命令-02

时间:2020年3月3日

+++++++++++++++++++++++++++++++++++++

 

#/usr/bin/env expect

set  ip  192.168.100.100

set  user  root

set  password  centos

set  timeout  5

spawn ssh ${user}@${ip}

expect {

  "yes/no" { send "yes\r" ; exp_continue }

  "password" { send "${password}\r" }

}

expect "#" {

  send "usedadd alice\r"

  send "echo 123456| passwd --stdin alie\r"

  send "id alice\r"

}

expect eof    #结束开始的spawn会话

 

posted @ 2020-03-03 19:36  叼着辣条的猫  阅读(533)  评论(0编辑  收藏  举报