本文共 381 字,大约阅读时间需要 1 分钟。
在主机A上编写并且执行Shell脚本,Shell脚本中需要ssh到主机B上执行交互命令。
在主机A上安装expect:
yum install expect
#!/usr/bin/expectset ip 192.168.1.102set pass yourpasswordset timeout 30spawn ssh root@$ipexpect { "(yes/no)" {send "yes\r"; exp_continue} "password:" {send "$pass\r"}}expect "root@*" {send "df -h\r"}expect "root@*" {send "exit\r"}expect eof
转载地址:http://lvbnl.baihongyu.com/