Friday, November 8, 2013

Script to configure User equivalence across the RAC nodes using SSH

echo "Enter Node1 name :"
read node1
echo "Enter No Of Nodes in RAC[1/2]:"
read noofnodes
echo "Make sure that /etc/hosts file contains all nodes ip addresess and hostnames "
parm="($node1)"
mkdir -p ~/.ssh
chmod 755 ~/.ssh
cd ~/.ssh
/usr/bin/ssh-keygen -t rsa
/usr/bin/ssh-keygen -t dsa
cat id_rsa.pub id_dsa.pub >> $node1
cat id_rsa.pub id_dsa.pub >> authorized_keys

if [ $noofnodes -eq 2 ]
then
echo "Enter Node2 name :"
read node2

scp $node1 $node2:~/.ssh/.
ssh $node2 "mkdir -p ~/.ssh;chmod 755 ~/.ssh;cd ~/.ssh;/usr/bin/ssh-keygen -t rsa;/usr/bin/ssh-keygen -t dsa;cat id_rsa.pub id_dsa.pub >> $node2;cat $node1 $node2 >> authorized_keys;chmod 644 authorized_keys"
scp $node2:~/.ssh/authorized_keys  ~/.ssh/.
echo "Execute Following Commands in Node $node2 as user `logname`"
echo "cd ~/.ssh"
echo "exec /usr/bin/ssh-agent \$SHELL"
echo "/usr/bin/ssh-add"
echo "Press Enter after executing above commands in node $node2 as user `logname`"
read aa
parm="($node1)|($node2)"
fi

cd ~/.ssh
chmod 644 authorized_keys
exec /usr/bin/ssh-agent $SHELL
/usr/bin/ssh-add

for lv in `cat /etc/hosts|grep -v "^#"|grep -i -E "$parm"`
do
echo $lv
ssh $lv date
ssh $lv date
done

No comments: