Created
August 28, 2015 16:26
-
-
Save devendranaga/248b64a9483e8ba70f83 to your computer and use it in GitHub Desktop.
get into a machine and exec a list of commands..
This file contains 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 | |
# Author: devnaga | |
## ip, username, password, command | |
# the csv file must look like the following | |
# ip,username,password,'command1; command2; command3' | |
# any sspace between the ',' will get you in trouble | |
import sys | |
import paramiko | |
import csv | |
if (len(sys.argv) != 2): | |
print "help: configuration" | |
exit(0) | |
clist = [] | |
f = open(sys.argv[1], "rt") | |
reader = csv.reader(f) | |
for row in reader: | |
clist.append(row) | |
f.close() | |
for row_val in clist: | |
ip=row_val[0] | |
usr=row_val[1] | |
psw=row_val[2] | |
command=row_val[3] | |
print ip, usr, psw, command | |
ssh = paramiko.SSHClient() | |
ssh.load_system_host_keys() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect(ip, username=usr, password=psw) | |
stdin, stdout, stderr= ssh.exec_command(command) | |
output = [] | |
output = stdout.readlines() | |
for item in output: | |
print item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment