#!/bin/bash
#by wwp 2020-10-14
#for openssh
>ip.list
passwd=6
rpm -q expect &>/dev/null
if [ $? -ne 0 ] ; then
	yum -y install expect >/dev/null && echo "expect installed"
fi
if [ ! -f ~/.ssh/id_rsa ] ; then
	ssh-keygen -P "" -f ~/.ssh/id_rsa
fi
for i in {130..180}
do
	{
	ip=192.168.188.$i
	ping -c1 -W1 $ip &>/dev/null
	if [ $? -eq 0 ];then
		echo "$ip" >> ip.list
		/usr/bin/expect <<-EOF
		spawn ssh-copy-id $ip
		expect {
			"yes/no" { send "yes\r"; exp_continue }
			"password:" { send "$passwd\r" }
		}
		expect eof
		EOF
	fi
	}&
done
wait
echo "all finish"
原文:https://www.cnblogs.com/wwp01/p/13830437.html