shell__ BuildTrust - wxl1989beyond/wxl GitHub Wiki
#!/bin/bash
genRsaKeys()
{
if -f "/root/.ssh/id_rsa.pub"; then
return 0
fi
expect -c "
spawn su – $userid -c \“ssh-keygen -t rsa\”
expect Enter*:
send \r
expect Enter*:
send \r
expect Enter*:
send \r
expect eof" >> $logfile 2>&1
if [ $? -ne 0 ];then
echo “make local rsa key pair failed.”
return 1
fi
}
buildTrust()
{
ipaddr=$1
#filter local ip
if ifconfig -a | grep -w $ipaddr >/dev/null
then
echo “buildTrust() | Skip to deal the local hosts”
return 1
fi
}
######################################MAIN#################################
#I need read machine info from config.txt.
#The file content like this: [ip username password]
#you need spilit records by newline.
#for example:
- 10.0.0.1 root password_1
- 10.0.0.2 root password_2
#you can add commit in config.txt with sharp, like this: - #10.0.0.3 root password_3
###########################################################################
CONFIG_FILE=$(pwd)/config.txt
if [ ! -f $CONFIG_FILE ];then
echo “please add config.txt in your dir[$(pwd)]”
exit 1
fi
#define logfile
logfile=$(pwd)/buildTrust.log
line_num=`cat $CONFIG_FILE|wc -l`
for ((index=1; index<=$line_num; index++));do
statement=“sed -n ’”$index"p’ $CONFIG_FILE"
line=$(eval $statement)
position_temp=${line:0:1}
if $position_temp != '#';then
echo $line
i=0
for e in $line;do
i=$((i+1))
if [ $i == 1 ]; then
IP=$e
fi
if [ $i == 2 ]; then
userid=$e
fi
if [ $i == 3 ]; then
userpass=$e
if [ -z “$userpass” ];then
userpass=$userid
fi
fi
done
done