##########mianmi.sh############
#!/usr/bin/expect set ip [lindex $argv 0] set password [lindex $argv 1] spawn ssh -o ConnectTimeout=5 -l root ${ip} expect { "(yes/no)? " { send "yes\r" expect "*assword: " send "$password\n" } "*assword: " { send "$password\n" } } expect "*assword:*" {exit 1} expect "*#*" {send "hostname\n"} expect "*#*" {send "exit\n"} expect eof exit 0
##########mianmiexecute.sh############
#!/bin/bash cat iplist | while read ip password
do /usr/bin/expect ssh_expect.sh $ip $password if [ $? -eq 0 ]; then echo ${ip} >> "/home/jialy/success_ip" else echo ${ip} >> "/home/jialy/fail_ip" fi done
iplist文件里放两列,一列ip,一列密码;
把mianmi.sh和mianmiexecute.sh放在同一个目录下,执行bash mianmiexecute.sh