#!/bin/bash
DIR=$(cd "$(dirname "$0")"; pwd)
FILE="$1"
IP_pool=$(awk ‘{print $1}‘ $DIR/$FILE)
cat /dev/null > $DIR/result.log
sshcopy(){
/usr/bin/expect <<-EOF
set timeout 15
spawn ssh-copy-id root@$1
expect "(yes/no)" { send "yes\r";exp_continue }
expect "password:" { send "$2\r" }
expect eof
EOF
}
cport(){
ssh -Tq root@$1 << EOF
sed -i -e ‘/Port 22/d‘ -e ‘1a Port 40000‘ /etc/ssh/sshd_config
service sshd restart
exit
EOF
}
test(){
echo "" | telnet $1 40000 | tee /tmp/$1.tmp
if grep "Connected" /tmp/$1.tmp &>/dev/null; then
echo "$1 setup successful" >> $DIR/result.log
else
echo "$1 setup failed" >> $DIR/result.log
fi
}
for i in ${IP_pool}; do
{
pwd=$(cat $DIR/$FILE | awk -v p=$i ‘$1==p{print $NF}‘)
sshcopy $i $pwd
cport $i
test $i
}&wait
done
rm -rf /tmp/*.tmp
原文:https://www.cnblogs.com/ly447742/p/14048914.html