Here is a function can not be achieved, is to let people enter their own password, interactive. Incoming passwords come in instead of being defined here.
Also hope pointing. Want to interact with Python here and let the user 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 [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 ... "
Implemented in Shell:
[[Email protected]hz-bf-02 ~]# cat /mnt/shell/denglv.sh #! /bin/bash#hexudong 345078833function trapper () { trap " int quit tstp term hup }function menu () { cat <<-EOF==============Host List================ 1) hz-mgdb-01 2) hz-mgdb-02 &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;3) hz-rds-01 4) HZ-RDS-02&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;5) hz-web-01--die 6) hz-web-02--die 7) mysql 9) hz-web-03 10) hz-web-04 &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;8) exit======================================= eof}function host () { case "$" in &NBSP;&NBSP;&NBSP;&NBSP;1) ssh [ email protected] ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;2) ssh [email protected] ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;3) ssh [email protected] ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;4) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; ssh [email protected] ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;5) ssh [email protected] ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;6) ssh [email protected] ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;7) mysql -h account -u User name-p$2 ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;9) ssh&nBsp [email protected] ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;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
Now use of Python, still needs to be perfected, welcome to help me improve
[[Email protected] ~]# cat /mnt/shell/denglv.py #!/usr/bin/evn pythonimport ospasswd = ' 123.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: &nBsp; 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: &nBsp; os.system (' ssh [email protected] ') if user_choice == 6: os.system (' ssh [email Protected] ') 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 ..."
This article from the "Clear Sky" blog, declined reprint!
Python Springboard Login Script