天天看点

Expect 安装 on centos7使用场景安装Shell脚本示例

使用场景

在主机A上编写并且执行Shell脚本,Shell脚本中需要ssh到主机B上执行交互命令。

安装

在主机A上安装expect:

yum install expect

Shell脚本示例

#!/usr/bin/expect

set ip 192.168.1.102
set pass yourpassword
set timeout 30
spawn ssh root@$ip
expect {
        "(yes/no)" {send "yes\r"; exp_continue}
        "password:" {send "$pass\r"}
}
expect "root@*"  {send "df -h\r"}
expect "root@*"  {send "exit\r"}
expect eof           

你现在的气质里,藏着你走过的路,读过的书,爱过的人。

继续阅读