这里有个功能没能实现,就是让人员自己输入密码,交互式的。传入密码进来,而不是在这里定义好。
还望指点。想在python这里实现交互让用户输入MySQL的密码
passwd = ‘123.com‘ logou_flag = False for 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 [email protected]" if user_choice == 2: print "ssh [email protected]" if user_choice == 3: logou_flag = True break if logou_flag: print "going to logout" break print "-----going to do something else....."
用shell方式实现:
[[email protected] ~]# 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 [email protected] ;; 2) ssh [email protected] ;; 3) ssh [email protected] ;; 4) ssh [email protected] ;; 5) ssh [email protected] ;; 6) ssh [email protected] ;; 7) mysql -h 账户 -u 用户名-p$2 ;; 9) ssh [email protected] ;; 10) ssh [email protected] ;; 8|*) exit esac } function main(){ while true do trapper clear menu read -p "please select:" num passwd host $num $passwd done } main
现在使用的python,还有待完善,欢迎帮我完善
[[email protected] ~]# cat /mnt/shell/denglv.py #!/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 """).strip() user_choice = int(user_choice) if user_choice == 1: os.system(‘ssh [email protected]‘) if user_choice == 2: os.system(‘ssh [email protected]‘) if user_choice == 3: os.system(‘ssh [email protected]‘) if user_choice == 4: os.system(‘ssh [email protected]‘) if user_choice == 5: os.system(‘ssh [email protected]‘) if user_choice == 6: os.system(‘ssh [email protected]‘) if user_choice == 7: os.system(‘mysql -h"保密" -u"保密" -p -A‘) if user_choice == 8: logou_flag = True break if logou_flag: print "going to logout" break print "-----going to do something else....."
时间: 2024-11-08 03:23:31