51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

SSH免交互expect

1.安装expect

[root@m01 ~]# yum install -y expect

2.编写expect脚本

#!/usr/bin/expect
set ip 10.0.0.51
set pass 123456
set timeout 30
spawn https://51tbox.com/ 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
赞(3)
未经允许不得转载:工具盒子 » SSH免交互expect