shell 结合expect实现ssh登录并执行命令

#!/bin/bash
ips=(
'127.0.0.1'
) for(( i=;i<${#ips[*]};i++))
do
expect <<EOF #这里的 expect <<EOF是指 在输入EOF时结束,expect <<-EOF,前面的-只是tab,不是空格,对应底下的EOF前面缩进还是顶格
set timeout
spawn ssh intfish@${ips[i]}
expect {
"*yes/no" { send "yes\r" }
"*password:" { send "root\r" }
}
expect -re ".*\[\$#\]"
send "df -h\r"
expect -re ".*\[\$#\]"
send "exit\r"
expect eof
EOF
done
上一篇:Apple-Watch开发1


下一篇:[EOJ629] 两开花