GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python/find_config_details.py at master · sambapython/python Expand file tree/ Copy pathfind_config_details.pyMore file actions 69 lines (60 loc) · 1.87 KB / Copy pathfind_config_details.pyFile metadata and controls69 lines (60 loc) · 1.87 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 ''' Input: Program takes host, username,password, sudo password and the config file that contains three columns. 1.command(command to execute in given vm ex: ls -l) 2. sudo(Does this command required sudo permission(1/0 or True/False)) 3. Value( result of the command) Output: Program adds the new column called "result" to the existing config file, stores 1/0 based on the value. ''' import paramiko as pmk ssh = pmk.SSHClient() import sys import os import pandas as pd ssh.set_missing_host_key_policy(pmk.AutoAddPolicy()) host = raw_input("Enter host:") username = raw_input("Enter username:") pwd= raw_input("Enter password:") sudo_pwd = raw_input("Enter sudo password:") sudo = "echo "+sudo_pwd+"| sudo -S " def get_cmd_data(cmd): ''' function returns an error message if the command gives any error message otherwise returns the command output This function has some problems, it's still need some improvement ''' stdin,stdout,stderr = ssh.exec_command(cmd) error = stderr.read() if error.find('password for ') != -1: return stdout.read() elif error: return error else: return stdout.read() while True: config_file_path = raw_input("Enter Config File Path:") if not os.path.isfile(config_file_path): option = raw_input("file is not there:\n\t Enter y to enter new file path \n\t Enter n to exit") if option == 'n': sys.exit(0) elif option == 'y': continue else: print "wrong option!!!!!!!!!!" else: file_data = pd.read_csv(config_file_path) break try: ssh.connect(host,username=username,password=pwd) res=[] for row in file_data.index: command = file_data.ix[row]['command'] root = file_data.ix[row]['sudo'] value = file_data.ix[row]['value'] if root: command = sudo+command res.append(1) if value == get_cmd_data(command) else res.append(0) file_data['result'] = res file_data.to_csv(config_file_path) except Exception as err: print err |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |