Python stepping stone login script

Source: Internet
Author: User

Python stepping stone login script
There is a function that cannot be implemented here, that is, to allow people to enter their own passwords and interact with each other. Pass in the password instead of defining it here. Hope you can give me some advice. I want to implement interaction in python to allow users to enter the MySQL password.

 passwd = '123.com'logou_flag = Falsefor i in range(3):    user_input = raw_input("Please input your passwd:").strip()    if len(user_input) ==0:continue    if user_input == passwd:        while True:            print "welcome login!"            user_choice = raw_input("""            1.hadoop-2            2.hadoop-3            3.exit            """).strip()            user_choice = int(user_choice)            if user_choice == 1:                print "ssh user@hadoop-2"            if user_choice == 2:                print "ssh user@hadoop-3"            if user_choice == 3:                logou_flag = True                break    if logou_flag:        print "going to logout"        break    print "-----going to do something else....."

 

Using shell:
[Root @ hz-bf-02 ~] # Cat/mnt/shell/denglv. sh #! /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 account-u username-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

 

The python currently in use is still to be improved. Please help me improve it.
[Root @ hz-bf-02 ~] # Cat/mnt/shell/denglv. py #! /Usr/bin/evn pythonimport ospasswd = '2017. com 'logou _ flag = Falsefor 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 """). 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 "confidential"-u "confidential"-p-a') if user_choice = 8: logou_flag = True break if logou_flag: print "going to logout" break print "----- going to do something else ....."

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.