SSH通信
- 主节点到从节点的通信模式
#!/bin/bash
USER_UID=root
USER_DIR=/root
IP_PW=root
ssh(){
cat >ssh.exp<<EOF
#!/usr/bin/expect
spawn ssh-copy-id -i $USER_DIR/.ssh/id_rsa.pub $SSH_IP
expect {
"*yes/no*" {send "yes\r";exp_continue}
"*password*" {send "$IP_PW\r"}
}
expect eof
EOF
chmod 755 ssh.exp
./ssh.exp > /dev/null
rm -f ./ssh.exp
}
if [ -f /etc/hosts ]
then
:
else
echo
echo "-------------------------------Please touch File: /etc/hosts --------------------------------"
exit 0
fi
if(rpm -qa | grep -q expect)
then
:
else
yum -y install expect > /dev/null
fi
if [ -f $USER_DIR/.ssh/id_rsa.pub ]
then
:
else
ssh-keygen
fi
for SSH_IP in `cat /etc/hosts | grep 192.* | awk '{print $2}'`
do
ssh
if [ $? -eq 0 ]
then
echo "--------------------$SSH_IP is ok-----------------------"
else
echo "--------------------$SSH_IP is failed-------------------"
fi
done