Created
October 23, 2014 18:43
-
-
Save nohtyp/24a5d35d8f6c730b5908 to your computer and use it in GitHub Desktop.
This script was a sample of remote manage server using python..I have a client (using bash..for testing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import os | |
| def print_menu(): | |
| print "--------------------------------" | |
| print "What would you like to do? " | |
| print "--------------------------------" | |
| print "Enter 1 for Creating a user account. " | |
| print "Enter 2 for Disabling a user account." | |
| print "Enter 3 for Enabling a user account. " | |
| print "Enter 4 for Change user's password. " | |
| print "Enter 5 for Unlock user's account. " | |
| print "Enter 6 to Search for User Account." | |
| print "Enter 7 to Search for Group Account." | |
| print "Enter 8 to QUIT!" | |
| def not_an_option(): | |
| print "This is not an option!" | |
| def your_choice(a): | |
| if a == 1: | |
| user_create_answer() | |
| elif a == 2: | |
| user_disable_user() | |
| elif a == 3: | |
| enable_user_account() | |
| elif a == 4: | |
| change_passwd() | |
| elif a == 5: | |
| unlock_user() | |
| elif a == 6: | |
| search_user() | |
| elif a == 7: | |
| search_group() | |
| else: | |
| print "Exiting" | |
| def rh_unlock(uname): | |
| print "Unlocking",uname,"account." | |
| def aix_unlock(uname): | |
| print "Unlocking",uname,"account." | |
| def unlock_user(): | |
| uuser = raw_input("Username to unlock: ") | |
| #write script to look in central database for user account | |
| print "Options for servers: All(Redhat & AIX), AIX, Redhat, Other(multiple servers)" | |
| server_answer = raw_input("Option: ") | |
| if server_answer == "all" or server_answer == "All" or server_answer == "ALL": | |
| print "Redhat & AIX systems" | |
| aix_unlock(uuser) | |
| rh_unlock(uuser) | |
| elif server_answer == "redhat" or server_answer == "Redhat" or server_answer == "REDHAT": | |
| print "Redhat" | |
| rh_unlock(uuser) | |
| elif server_answer == "aix" or server_answer == "Aix" or server_answer == "AIX": | |
| print "AIX" | |
| aix_unlock(uuser) | |
| elif server_answer == "other" or server_answer == "Other" or server_answer == "OTHER": | |
| print "Enter server names seperated by a space." | |
| #create function to take specific servers!!! | |
| else: | |
| print "The script exited!!" | |
| def rh_create(fname,lname,unameid,pgroup,uname): | |
| username = 'tfoster' | |
| #command = "/home/tfoster/create " + fname + " " + lname + " " + unameid + " " + pgroup + " " + uname | |
| command = "/home/tfoster/create " + uname | |
| server = 'chris' | |
| os.system("ssh -qn %s@%s %s" %(username, server, command)) | |
| #need to loop through server list for Redhat systems | |
| #create bash script for each system so it can run | |
| def aix_create(fname,lname,unameid,pgroup,uname): | |
| print fname,lname | |
| #need to loop through server list for AIX systems | |
| #create bash script for each system so it can run | |
| def user_create_answer(): | |
| fname = raw_input("User's First name: ").strip().lowercase() | |
| while fname == "": | |
| print "First name is empty." | |
| fname = raw_input("User's First name: ").strip().lowercase() | |
| lname = raw_input("Users's Last name: ").strip().lowercase() | |
| while lname == "": | |
| print "Last name is empty." | |
| lname = raw_input("Users's Last name: ").strip().lowercase() | |
| unameid = raw_input("User's ID (ex.. 501): ").strip().lowercase() | |
| while unameid == "" or unameid == '0' or unameid == 'root': | |
| try: | |
| print "You have not entered a userid for user",fname,lname | |
| unameid = input("User's ID (ex.. 501): ").strip().lowercase() | |
| except (NameError, ValueError): | |
| print "Oops!" | |
| pgroup = raw_input("Primary group: ").strip().lowercase() | |
| while pgroup == "" or pgroup == '0' or pgroup == 'root': | |
| try: | |
| print "You have not entered a Primary group for user",fname,lname | |
| pgroup = input("Primary group: ").strip().lowercase() | |
| except (NameError, ValueError): | |
| print "Oops!" | |
| uname = raw_input("UserName: ").strip().lowercase() | |
| while uname == "" or uname == 'root': | |
| print "You have not chosen a user name for user",fname,lname,"." | |
| uname = raw_input("UserName: ").strip().lowercase() | |
| print "Options for servers: All(Redhat & AIX), AIX, Redhat, Other(multiple servers)" | |
| server_answer = raw_input("Option: ") | |
| if server_answer == "all" or server_answer == "All" or server_answer == "ALL": | |
| print "Redhat & AIX systems" | |
| aix_create(fname,lname,unameid,pgroup,uname) | |
| rh_create(fname,lname,unameid,pgroup,uname) | |
| elif server_answer == "redhat" or server_answer == "Redhat" or server_answer == "REDHAT": | |
| #print "Redhat" | |
| rh_create(fname,lname,unameid,pgroup,uname) | |
| elif server_answer == "aix" or server_answer == "Aix" or server_answer == "AIX": | |
| print "AIX" | |
| aix_create(fname,lname,unameid,pgroup,uname) | |
| elif server_answer == "other" or server_answer == "Other" or server_answer == "OTHER": | |
| print "Enter server names seperated by a space." | |
| #create function to take specific servers!!! | |
| else: | |
| print "The script exited!!" | |
| def enable_user_account(): | |
| euser = raw_input("Username to enable: ") | |
| #write script to look in central database for user account | |
| print "Options for servers: All(Redhat & AIX), AIX, Redhat, Other(multiple servers)" | |
| server_answer = raw_input("Option: ") | |
| if server_answer == "all" or server_answer == "All" or server_answer == "ALL": | |
| print "Redhat & AIX systems" | |
| aix_enable(euser) | |
| rh_enable(euser) | |
| elif server_answer == "redhat" or server_answer == "Redhat" or server_answer == "REDHAT": | |
| print "Redhat" | |
| rh_enable(euser) | |
| elif server_answer == "aix" or server_answer == "Aix" or server_answer == "AIX": | |
| print "AIX" | |
| aix_enable(euser) | |
| elif server_answer == "other" or server_answer == "Other" or server_answer == "OTHER": | |
| print "Enter server names seperated by a space." | |
| #create function to take specific servers!!! | |
| else: | |
| print "The script exited!!" | |
| def aix_enable(uname): | |
| print "Enabling",uname,"account." | |
| def rh_enable(uname): | |
| print "Enabling",uname,"account." | |
| def user_disable_user(): | |
| disuser = raw_input("UserName to disable: ") | |
| #write script to look in central database for user account | |
| print "Options for servers: All(Redhat & AIX), AIX, Redhat, Other(multiple servers)" | |
| server_answer = raw_input("Option: ") | |
| if server_answer == "all" or server_answer == "All" or server_answer == "ALL": | |
| print "Redhat & AIX systems" | |
| aix_disable(disuser) | |
| rh_disable(disuser) | |
| elif server_answer == "redhat" or server_answer == "Redhat" or server_answer == "REDHAT": | |
| print "Redhat" | |
| rh_disable(disuser) | |
| elif server_answer == "aix" or server_answer == "Aix" or server_answer == "AIX": | |
| print "AIX" | |
| aix_disable(disuser) | |
| elif server_answer == "other" or server_answer == "Other" or server_answer == "OTHER": | |
| print "Enter server names seperated by a space." | |
| #create function to take specific servers!!! | |
| else: | |
| print "The script exited!!" | |
| def aix_disable(uname): | |
| print "Disabling",uname,"account." | |
| #create script to loop through servers to disable account | |
| def rh_disable(uname): | |
| print "Disabling",uname,"account." | |
| #create script to loop through servers to disable account | |
| def rh_passwd(uname): | |
| print "changing password for",uname,"user's account." | |
| #create script to loop through servers to change password for account | |
| def aix_passwd(uname): | |
| print "changing password for",uname,"user's account." | |
| #create script to loop through servers to change password for account | |
| def change_passwd(): | |
| userpass = raw_input("UserName for password change: ") | |
| #write script to look in central database for user account | |
| print "Options for servers: All(Redhat & AIX), AIX, Redhat, Other(multiple servers)" | |
| server_answer = raw_input("Option: ") | |
| if server_answer == "all" or server_answer == "All" or server_answer == "ALL": | |
| print "Redhat & AIX systems" | |
| aix_passwd(userpass) | |
| rh_passwd(userpass) | |
| elif server_answer == "redhat" or server_answer == "Redhat" or server_answer == "REDHAT": | |
| print "Redhat" | |
| rh_passwd(userpass) | |
| elif server_answer == "aix" or server_answer == "Aix" or server_answer == "AIX": | |
| print "AIX" | |
| aix_passwd(userpass) | |
| elif server_answer == "other" or server_answer == "Other" or server_answer == "OTHER": | |
| print "Enter server names seperated by a space." | |
| #create function to take specific servers!!! | |
| else: | |
| print "The script exited!!" | |
| def program(): | |
| print_menu() | |
| choice = 0 | |
| while choice != 8: | |
| choice = input("Choice: ") | |
| if choice < 1 or choice > 8: | |
| not_an_option() | |
| else: | |
| your_choice(choice) | |
| program() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment