expect脚本

Expect脚本批量执行命令

#!/bin/bash
cat /root/iplist|while read line
do
a=($line)
   expect <<EOF                 
   set timeout 3
   spawn ssh root@${a[0]}
   expect {
       "*yes/no" { send "yes\r" }
       "*password:" { send "${a[1]}\r" }
   }
   expect -re ".*\[\$#\]"
   send "df -h\r"
   expect -re ".*\[\$#\]"
   send "exit\r"
   expect eof
EOF
done
ps:iplist
192.168.1.11 admin@123
192.168.1.12 admin@223
posted @ 2020-07-29 19:43  深入决定深度  阅读(187)  评论(0)    收藏  举报