centos7 expect

在主机A上安装expect:

yum install expect

Shell脚本示例

  1. #!/usr/bin/expect
  2.  
  3. set ip 192.168.1.102
  4. set pass yourpassword
  5. set timeout 30
  6. spawn ssh root@$ip
  7. expect {
  8. "(yes/no)" {send "yes\r"; exp_continue}
  9. "password:" {send "$pass\r"}
  10. }
  11. expect "root@*" {send "df -h\r"}
  12. expect "root@*" {send "exit\r"}
  13. expect eof
posted @ 2020-07-22 08:17  羽冲  阅读(476)  评论(0编辑  收藏  举报