1、测试主机是否在线
#!/bin/bash
#创建一个IP地址文件。
>ip.txt (清空文本)
#使用for循环ping测试主机是否在线。
for i in {2..254}
do
{
#学员请注意练习环境的IP地址,可能与示例中不同。
ip=192.168.122.$i
ping -c1 -W1 $ip &> /dev/null
if [ $? -eq 0 ];then
echo "$ip" >> ip.txt
/usr/bin/expect <<-EOF (使得expect能在shell里运行)
set timeout 10
spawn ssh-copy-id $ip
expect {
"yes/no" { send "yes
"; exp_continue }
"password:" { send "centos
" }
}
expect eof
EOF
fi
}&
done
wait
echo "finishi..."