登录脚本

#! /bin/bash
#hexudong  345078833
function trapper(){
        trap '' INT QUIT TSTP TERM HUP  
}
function menu(){
        cat <<-EOF
==============Host List================
        1)hz-mgdb-01
        2)hz-mgdb-02
        3)hz-rds-01
        4)hz-rds-02
        5)hz-web-01--die
        6)hz-web-02--die
        7)mysql
        9)hz-web-03
       10)hz-web-04
        8)exit
=======================================
        EOF
}
function host(){
        case "$1" in
          1)
            ssh $USER@hz-mgdb-01
            ;;
          2)
            ssh $USER@hz-mgdb-02
            ;;
          3)
            ssh $USER@hz-rds-01
            ;;
          4)
            ssh $USER@hz-rds-02
            ;;
          5)
            ssh $USER@hz-web-01
            ;;
          6)
            ssh $USER@hz-web-02
            ;;
          7)
            mysql -h RDS -u adminla -p$2
            ;;
          9)
            ssh $USER@hz-web-03
            ;;
          10)
            ssh $USER@hz-web-04
            ;;
          8|*)
            exit
        esac
}
function main(){
        while true
          do
            trapper
            clear
            menu
            read -p "please select:" num passwd
            host $num $passwd
        done
}
main


#!/usr/bin/evn python
import os
passwd = '123.com'
logou_flag = False
for i in range(3):
    user_input = raw_input("""Please input your passwd:
No password,Please quit!!!
Or Looking for xudong   :""").strip()
    if len(user_input) ==0:continue
    if user_input == passwd:
        while True:
            print "welcome login!"
            user_choice = raw_input("""
                1.hz-mgdb-01
                2.hz-mgdb-02
                3.hz-rds-01
                4.hz-rds-02
                5.hz-web-03
                6.hz-web-04
                7.mysql
                8.exit
                9.hz-web-05
                10.hz-web-06
            """).strip()
            user_choice = int(user_choice)
            if user_choice == 1:
                os.system('ssh root@hz-mgdb-01')
            if user_choice == 2:
                os.system('ssh root@hz-mgdb-02')
            if user_choice == 3:
                os.system('ssh root@hz-rds-01')
            if user_choice == 4:
                os.system('ssh root@hz-rds-02')
            if user_choice == 5:
                os.system('ssh root@hz-web-03')
            if user_choice == 6:
                os.system('ssh root@hz-web-04')
            if user_choice == 7:
                os.system('mysql -h"RDS" -u"adminla" -p -A')
            if user_choice == 8:
                logou_flag = True
                break
            if user_choice == 9:
                os.system('ssh root@hz-web-05')
            if user_choice ==10:
                os.system('ssh root@hz-web-06')
    if logou_flag:
        print "going to logout"
        break
    print "-----going to do something else....."


本文出自 “晴空” 博客,谢绝转载!

你可能感兴趣的:(登录脚本)