- A+
Version:1.1
使用方法:sh 此脚本 Host Port Password
- #!/bin/bash
- [ -f /etc/init.d/functions ] && source /etc/init.d/functions
- [ -f /etc/profile ] && source /etc/profile
- Host="$1"
- Port="$2"
- Password="$3"
- if [ $# -ne 3 ];then
- echo -e "\033[33m Usage: $0 [Host] [Port] [Password] \033[0m"
- exit 1
- fi
- function CHECK_SSHPASS() {
- Sshpass_Num=`rpm -qa|grep "sshpass" 2>/dev/null |wc -l`
- if [ ${Sshpass_Num} -lt 1 ];then
- echo -e "\033[33m No sshpass command was found, Ready to download...\033[0m"
- yum install -y sshpass &>/dev/null
- Sshpass_Num=`rpm -qa|grep "sshpass" 2>/dev/null |wc -l`
- if [ ${Sshpass_Num} -lt 1 ];then
- echo -e "\033[31m command download false...\033[0m"
- exit 2
- fi
- fi
- }
- function GENERATE_KEY() {
- if [ ! -f /tmp/ssh_dsa_Overdue_verification.txt ]
- then
- touch /tmp/ssh_dsa_Overdue_verification.txt
- /bin/rm -r /root/.ssh/id* >/dev/null 2>&1
- ssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" -q
- fi
- }
- function OK_FALSE() {
- RETVAL=$?
- if [ $RETVAL -eq 0 ];then
- action "Key distribution..." /bin/true
- else
- action "Key distribution..." /bin/false
- fi
- }
- function DISTRIBUTE_KEY() {
- for ip in "${Host}"
- do
- sshpass -p "${Password}" ssh-copy-id -i /root/.ssh/id_dsa.pub \
- -o StrictHostKeyChecking=no -p{Port} root@{Host} >/dev/null 2>&1
- done
- OK_FALSE
- }
- function main() {
- CHECK_SSHPASS
- GENERATE_KEY
- DISTRIBUTE_KEY
- }
- main
- exit 0