Posts

Showing posts from September, 2018

Python script to compare and merge excel files

Here I’m talking about a cool Python module using that you can compare two sheets in an excel sheet for a common value and merge the sheets. First you need to install the module “pandas” for the solution. Python script is as below : import pandas as pd source1_df = pd.read_excel('a.xlsx', sheetname='Sheet1') source2_df = pd.read_excel('a.xlsx', sheetname='Sheet2') joined_df = pd.merge(source1_df,source2_df,on='Serial',how='outer') joined_df.to_excel('result.xlsx') Note : replace the sheet1 and sheet2 with actual name of the pages and use the correct primary key name(Here “Serial”; case sensitive) Eg : sheet1 as below Serial Hostname 123 abc 234 bcd 345 cde Sheet2 as below Serial Model 234 Sparc 345 IBM 567 HP After executing the python script, output comes  as below :   Serial Hostname Model

Python script to check ssh login on multiple hosts against a common password

Below python script can be used to check ssh login on multiple hosts against a common password and print the output to different files based on status. It prompts user to enter the password and check it against all the hostname in the input_file. To speed up the process, I’m using multithreading module which run the jobs in parallel to accomplish the task faster. This script works with Python3.5 version #!/bin/python3 import threading, time, paramiko, socket, getpass from queue import Queue locke1 = threading.Lock() q = Queue() #Check the login def check_hostname(host_name, pw_r): with locke1: print ("Checking hostname :"+str(host_name)+" with " + threading.current_thread().name) file_output = open('output_file','a') file_success = open('success_file','a') file_failed = open('failed_file','a') file_error = open('error_file','a') ssh = paramiko.S