usage () {
if [ ! $# -eq 2 ];then
echo "Usage:/bin/sh $0 -f host_list_file"
exit 0
fi
}
auth () {
ID=`id|awk -F"[=()]+" '{print$2}'`
if [ $ID -ne 0 ];then
echo "This tool should be running under root. Exit."
exit 0
fi
}
pubkey () {
#Create ssh_key
if [ ! -f ~/.ssh/id_dsa ];then
echo "The ssh key is not exist. It will be created..."
echo -e "\n"|ssh-keygen -t dsa -N "" >/dev/null2>&1
echo "The key is created successful."
fi
#Disable StrictHostKeyChecking
grep "^StrictHostKeyChecking no"/etc/ssh/ssh_config >/dev/null 2>&1
if [ $? -ne 0 ];then
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config&>/dev/null
fi
}
deploy () {
#input root and password
echo "Deploying pub key."
read -p "Please type the remoteaccount:" ac
read -s -p "Please type the remotepassword:" pw
echo
#Deploy pub key
if [ -f $Hosts ];then
forn in `cat $Hosts`
do
sshpass -p $pw ssh-copy-id -i .ssh/id_dsa.pub $ac@$n &>/dev/null
if [ $? -eq 0 ];then
action "Deploying pub_key for $n......Success!" /bin/true
else
action "Deploying pub_key for $n......Failed!" /bin/false
fi
done
else
exit 0
fi
}