Skip to content

Instantly share code, notes, and snippets.

@devendranaga
Created August 28, 2015 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devendranaga/248b64a9483e8ba70f83 to your computer and use it in GitHub Desktop.
Save devendranaga/248b64a9483e8ba70f83 to your computer and use it in GitHub Desktop.
get into a machine and exec a list of commands..
#!/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