作者: 薄荷冰           Linux基础  |  网站架构  |  数据库  |  监控报警  |  shell系列  |  常用工具  |  常见问题


 

导航

 
#!/bin/bash
############################################################
# $Name:         Springboard.sh
# $Version:      v1.0
# $Functions:
# $Author:       Jeson Li
# $organization: www.lzbbg.cn
# $Create Date:  2017-03-10
# $Mail:         libobin@tom.com
# $Description:  This scripts funcsion is tiao ban ji
############################################################
# Control login users using springboard
# echo '[ $UID -ne 0 ] && [ $USER != "jeson" ] && source /server/tools_scripts/Springboard.sh' /etc/profile.d/tb.sh
remote_user=$USER
remote_password=123456
remote_Port=52113
path_FenFa_sshKey_exp=/server/tools_scripts/send_sshkey.exp
while true
do
    trap '' INT EXIT TSTP TERM HUP
    clear
    cat         <<-menu
  ============= Host List =============
    $(awk 'NR>2&&NF>2{print "   "NR-2"\t",$1"\t"$2}' /etc/hosts)
  -------------------------------------
   0     EXIT "Only for root and jeson user !"
  -------------------------------------
    menu
    read -p "Please select number:" num
    if [ $num -eq 0 ];then
        exit 1
    elif [ $num -gt 0 ];then
        ssh -p52113 $USER@$(awk -F"[ \t]+" "NR==$(($num+2)) && NF>2"'{print $2}' /etc/hosts)
    elif [ "$num" == "sshkey" ];then
        sudo yum -y install expect
        [ ! -f ~/.ssh/id_dsa ] && { ssh-keygen -t dsa -q -P '' -f ~/.ssh/id_dsa>/dev/null ; }
        for remote_ip in $(awk -F"[ \t]+" "NR>2 && NF>2"'{print $2}' /etc/hosts)
        do
            expect $path_FenFa_sshKey_exp $remote_Port $remote_user $remote_password $remote_ip ~/.ssh/id_dsa.pub
        done
    fi
done 

 

posted on 2018-12-27 20:17  薄荷冰  阅读(147)  评论(0)    收藏  举报