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 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
欢迎来撩 : 汇总all