#!/bin/bash
IP=`awk '{print $1}' /home/bash/mima.txt`

for i in $IP
do
{        port=`grep $i /home/bash/mima.txt|awk '{print $2}'`
        pawd=`grep $i /home/bash/mima.txt|awk '{print $3}'`
expect << EOF
spawn ssh -p $port root@$i;
    expect {
         "(yes/no)?" {  send "yes\r" }
         "password:" { send "$pawd\n" }
         }
    expect "#"
send "uptime\r"
expect eof
EOF
}&
done

mima.txt是密码文件
调用expect来执行ssh的交互式登录