1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #!/bin/bash
host_file="host_tmp.txt"
host=$1 passwd=$2 username="root" [ $# -ne 2 ] && echo "Please input parameter host password" && exit echo "$host $username $passwd " >$host_file
while read host ;do #ip user passwd ip=$(echo $host|awk '{print $1}') user=$(echo $host|awk '{print $2}') passwd=$(echo $host|awk '{print $3}') expect <<EOF spawn ssh-copy-id -i $user@$ip expect { "yes/no" {send "yes\n";exp_continue} "password" {send "$passwd\n"} } expect eof EOF echo "$host -- $user 完成了免密登录!" done < $host_file rm -f $host_file
|